Open In App
Related Articles

JavaScript Array reverse() Method

Improve Article
Improve
Save Article
Save
Like Article
Like

JavaScript Array.reverse() Method is used for the in-place reversal of the array. This method reverses the order of the array. The first element of the array becomes the last element and the last one becomes the first. It mutates the original array. We can also use the Array.toReversed() which returns the new array with the elements in the reverse order.

Syntax:

arr.reverse()

Parameters: This method does not accept any parameter

Return value: This method returns the reference of the reversed original array.

Example 1: The below examples illustrate the JavaScript Array reverse() Method

JavaScript




function func() {
    // Original Array
    let arr = ['Portal', 'Science',
        'Computer', 'GeeksforGeeks'];
    console.log(arr);
 
    // Reversed array
    let new_arr = arr.reverse();
    console.log(new_arr);
}
func();


Output

[ 'Portal', 'Science', 'Computer', 'GeeksforGeeks' ]
[ 'GeeksforGeeks', 'Computer', 'Science', 'Portal' ]

Example 2: In this example, the reverse() method reverses the sequence of the array elements of arr.

JavaScript




function func() {
 
    // Original Array
    let arr = [34, 234, 567, 4];
    console.log(arr);
 
    // Reversed array
    let new_arr = arr.reverse();
    console.log(new_arr);
}
func();


Output

[ 34, 234, 567, 4 ]
[ 4, 567, 234, 34 ]

We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.

Supported Browsers: The browsers supported by the JavaScript Array reverse() method are listed below:

  • Google Chrome 1.0 and above
  • Microsoft Edge 12 and above
  • Mozilla Firefox 1.0 and above
  • Safari 1 and above
  • Opera 4 and above

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 07 Jul, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials