JavaScript Array reverse() Method


Advertisements


Description

Javascript array reverse() mmethod reverses the element of an array. The first array element becomes the last and the last becomes the first.

Syntax

Its syntax is as follows −

array.reverse();

Return Value

Returns the reversed single value of the array.

Example

Try the following example.

<html>
   <head>
      <title>JavaScript Array reverse Method</title>
   </head>
   
   <body>
   
      <script type="text/javascript">
         var arr = [0, 1, 2, 3].reverse();
         document.write("Reversed array is : " + arr ); 
      </script>
      
   </body>
</html>

Output

Reversed array is : 3,2,1,0 

javascript_arrays_object.htm