JavaScript | Array reverse()

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

Syntax:
arr.reverse()

Argument
This function does not take any argument.

Return value
This function returns the reference of the reversed original array.

Example for the above function is provided below:

Example 1:



var arr = [34, 234, 567, 4];
print(arr);
var new_arr = arr.reverse();
print(new_arr);

Output:

34, 234, 567, 4
4, 567, 234, 34

In this example the function reverse() reverses the sequence of the array elements of arr.

Code for the above function is provided below:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
// JavaScript to illustrate reverse() function
  
function func() {
  
    //Original Array
    var arr = [34, 234, 567, 4];
    document.write(arr);
  
    //Reversed array
    var new_arr = arr.reverse();
    document.write("<br>");
    document.write(new_arr);
}
func();
</script>

chevron_right


Output:

34, 234, 567, 4
4, 567, 234, 34


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.