Skip to content
Advertisement

Reverse array in Javascript without mutating original array

Array.prototype.reverse reverses the contents of an array in place (with mutation)…

Is there a similarly simple strategy for reversing an array without altering the contents of the original array (without mutation)?

Advertisement

Answer

You can use slice() to make a copy then reverse() it

JavaScript

JavaScript
Advertisement