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});
1let array1 = ["yes", "no", "maybe", "always", "sometimes", "never", "if"];
2let array2 = [5,8,2,9,5,6,3,1];
3
4function reverseArray(arr) {
5 var newArray = [];
6 for (var i = arr.length - 1; i >= 0; i--) {
7 newArray.push(arr[i]);
8 }
9 return newArray;
10}
11
12reverseArray(array1); // ["if", "never", "sometimes", "always", "maybe", "no", "yes"]
13reverseArray(array2); // [1, 3, 6, 5, 9, 2, 8, 5]