1var arr = [34, 234, 567, 4];
2print(arr);
3var new_arr = arr.reverse();
4print(new_arr);
5
1const array1 = [1,2,3,4];
2console.log('array1:', array1);
3//"array1:" Array [1, 2, 3, 4]
4
5const reversed = array1.reverse();
6console.log('reversed:', reversed);
7//"reversed:" Array [4, 3, 2, 1]
8
9// Careful: reverse is destructive -- it changes the original array.
10console.log('array1:', array1);
11//"array1:" Array [4, 3, 2, 1]
1var reversed = array.map(function reverse(item) {
2 return Array.isArray(item) && Array.isArray(item[0])
3 ? item.map(reverse)
4 : item.reverse();
5});
1// reverse array with recursion function
2function reverseArray (arr){
3if (arr.length === 0){
4return []
5}
6 return [arr.pop()].concat(reverseArray(arr))
7}
8console.log(reverseArray([1, 2, 3, 4, 5]))