Open In App

What is the use of reverse() method in JavaScript Arrays ?

Last Updated : 31 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The reverse() method in JavaScript is used to reverse the order of elements in an array. It modifies the original array and returns the reversed array. This means that the last element becomes the first, the second-to-last becomes the second, and so on.

Example: Here, the reverse() the method is applied to the myArray, resulting in the original order being reversed.

Javascript




let myArray = [1, 2, 3, 4, 5];
 
// Reverse the order of elements in the array
myArray.reverse();
 
console.log(myArray); // Output: [5, 4, 3, 2, 1]


Output

[ 5, 4, 3, 2, 1 ]


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads