Answers for "how to reverse an array in javascript"

21

reversing an array in js

var arr=[1,2,5,6,2]
arr.reverse()
Posted by: Guest on June-26-2020
5

reverse number javascript

// Function to reverse Number
function reverseNum(n) {
  let r = n.toString().split('').reverse().join('');
  return Math.sign(n) * parseInt(r);
}

// Call
reverseNum(-267);
reverseNum(31522);

// Outputs
-762
22513
Posted by: Guest on March-12-2020
33

javascript reverse array

var arr = [34, 234, 567, 4];
print(arr);
var new_arr = arr.reverse();
print(new_arr);
Posted by: Guest on November-16-2019
1

js reverse nested array

var reversed = array.map(function reverse(item) {
    return Array.isArray(item) && Array.isArray(item[0]) 
               ? item.map(reverse) 
               : item.reverse();
});
Posted by: Guest on April-27-2020
1

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]
Posted by: Guest on June-06-2020
5

how to reverse an array in javascript

array = [1 2, 3]
reversed = array.reverse()
Posted by: Guest on January-21-2021

Code answers related to "how to reverse an array in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language