Below is the example of Array reverse() method.
- Example:
<script>functionfunc() {// Original Arrayvararr = ['Portal','Science','Computer','GeeksforGeeks'];document.write(arr);// Reversed arrayvarnew_arr = arr.reverse();document.write("<br>");document.write(new_arr);}func();</script>chevron_rightfilter_none - Output:
Portal,Science,Computer,GeeksforGeeks GeeksforGeeks,Computer,Science,Portal
The arr.reverse() method 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()
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: In this example the reverse() method reverses the sequence of the array elements of arr.
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
Code for the above method is provided below:
Program 1:
<script> 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> |
Output:
34, 234, 567, 4 4, 567, 234, 34
Supported Browsers: The browsers supported by JavaScript Array reverse() method are listed below:
- Google Chrome 1.0
- Microsoft Edge 5.5
- Mozilla Firefox 1.0
- Safari
- Opera
Recommended Posts:
- How to use map() on an array in reverse order with JavaScript ?
- JavaScript | typedArray.reverse() with Examples
- Reverse a String in JavaScript
- JavaScript | Reverse a string in place.
- TypeScript | Array reverse() Method
- How to compare two JavaScript array objects using jQuery/JavaScript ?
- Node.js | dnsPromises.reverse() Method
- Lodash _.prototype.reverse() Method
- JavaScript Course | Understanding Code Structure in JavaScript
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | What is JavaScript ?
- JavaScript Course | Operators in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | Variables in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Objects in JavaScript
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.


