reverse in js code example

Example 1: reversing an array in js

var arr=[1,2,5,6,2]
arr.reverse()

Example 2: javascript reverse array

var arr = [34, 234, 567, 4];
print(arr);
var new_arr = arr.reverse();
print(new_arr);

Example 3: how to reverse an array in javascript

array = [1 2, 3]
reversed = array.reverse()

Example 4: js array reverse

[34, 234, 567, 4].reverse();

Example 5: array reverse algorithm in js

let array1 = ["yes", "no", "maybe", "always", "sometimes", "never", "if"];
let array2 = [5,8,2,9,5,6,3,1];

function reverseArray(arr) {
  var newArray = [];
  for (var i = arr.length - 1; i >= 0; i--) {
    newArray.push(arr[i]);
  }
  return newArray;
}

reverseArray(array1); // ["if", "never", "sometimes", "always", "maybe", "no", "yes"]
reverseArray(array2); // [1, 3, 6, 5, 9, 2, 8, 5]

Example 6: reverse array javascript

var rev = arr.reverse();