javascriptarraysfor-loopreversing

Reverse into new array VS reverse in place


I have been trying to reverse an array, first by using push and creating a new array, and then second by using destructuring and mutating the original array.

I'm wondering which of the two runs faster, and why?


Solution

  • Assuming your code is optimized:

    Also note that may use the built-in Array.prototype.reverse() method as well.