Categories
JavaScript Answers

How to reverse array in JavaScript without mutating original array?

Spread the love

To reverse array in JavaScript without mutating original array, we copy the array before calling reverse.

For instance, we write

const newArray = [...array].reverse();

to copy the array with the spread operator.

And then we call reverse to reverse the copied array.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.