JavaScript Array class have one method reverse() which will reverse the order of element into the array. This has a simple syntax as follows:
arrayname.reverse()
In this example we have created an array "arr" which contains three elements. Now we can reverse the array elements order by using the method reverse(). Here is the full example code of JavaScript array reverse() method as follows:
| <html> <head> <title>JavaScript array reverse() example</title> <script type="text/javascript"> var arr = new Array(3); arr[0]="1"; arr[1]="2"; arr[2]="3"; document.write("<b>Array 'arr' is </b>=>"+arr+"<br> "); document.write("<b>Reversed array is</b> =>"+arr.reverse()+"<br> "); </script> </head> <body> <h2> Example of reversing an array </h2> </body> </html> |
Output:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: JavaScript array reverse example
Post your Comment