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.