How do I reverse an array in JavaScript?

To reverse an array in JavaScript, you can use the array.reverse() method. The reverse() method allows you to reverse the order of the elements of an array so that the first element of the array becomes the last and the last element becomes the first. The reverse() method overwrites the original array (a new array is not created, but a reference to the currently modified array is returned). If the array is not contiguous (there are gaps between indices), then the reverse() method fills these gaps with elements with the value "undefined". You can also reverse the array manually using a for loop, but this will be slower than using the built-in array.reverse() method. In this JavaScript array reverse example, we use the reverse() method. Below you can see more examples of the JavaScript reverse arrays with a detailed description of each method. Click Execute to run the JavaScript Reverse Array online and see the result.
Loading...