Home Java Javascript-array JavaScript array reverse example
Questions:Ask|Latest



JavaScript array reverse example
Posted on: November 5, 2008 By Deepak Kumar
JavaScript Array class have one method reverse() which will reverse the order of element into the array.

JavaScript array reverse example

     

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:

Download Source Code


Recommend the tutorial

Ask Questions?    Discuss: JavaScript array reverse example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Sonagra
September 11, 2011
javascript

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