Reverse array in Javascript without mutating original array -


array.prototype.reverse can used reverse contents of array in place mutation...

is there simple strategy reversing array without altering contents of original array?

i think can use slice() make copy reverse() it

var newarray = array.slice().reverse(); 

var array = ['a', 'b', 'c', 'd', 'e'];  var newarray = array.slice().reverse();    console.log('a', array);  console.log('na', newarray);


Comments