The Wayback Machine - https://web.archive.org/web/20230326131247/https://www.geeksforgeeks.org/javascript-array-reverse-method/
Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Array reverse() Method

Improve Article
Save Article
  • Last Updated : 20 Dec, 2022
Improve Article
Save Article

JavaScript Array.reverse() Method is used for the in-place reversal of the array. The first element of the array becomes the last element and vice versa.

Syntax:

arr.reverse()

Parameters: This method does not accept any parameter

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

Below examples illustrate the JavaScript Array reverse() Method:

Example 1: 

JavaScript




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

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




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

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 referencearticle.

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.


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!