This post will discuss how to reverse an array in JavaScript.

1. Using Array.prototype.reverse() function

The standard method to reverse an array in JavaScript is using the reverse() method. This method operates in-place, meaning that the original array is modified, and no reversed copy is created.

Download  Run Code

 
If you don’t want to modify the original array, call the reverse() method on a copy of the array. You can clone the array by using slicing or ES6 Spread operator.

Download  Run Code

2. Using Array.prototype.map() function

The map() method is often used to create a new array, where each element of it results from some operation applied to elements of another array. To reverse an array, you can do like:

Download  Run Code

 
The following code uses the Spread operator to clone the array and then uses the map() method to call pop() on the original array and move the returned element to a new array.

Download  Run Code

3. Using Lodash Library

If you’re using the Lodash JavaScript library in your project, you can use the reverse() method to in-place reverse an array.

Download Code

4. Custom Routine

Finally, you can write your own custom routine to reverse an array in-place or return a reverse copy of its instance.

Download  Run Code

That’s all about reversing an array in JavaScript.