To sort an array in reverse, we can use reverse method directly. See below example,
1. Reverse an Integer array
2. Reverse an string array
Note: Reverse means , just reverse( End to start) the output. not any order.
1. Reverse an Integer array
let arr = [1, 2, 3, 4, 5]; arr.reverse(); alert( arr ); // 5,4,3,2,1
2. Reverse an string array
var fruitsTest = ["Banana", "Orange", "Apple", "Mango"]; fruitsTest.reverse();
Note: Reverse means , just reverse( End to start) the output. not any order.
No comments:
Post a Comment