What is array reverse in JavaScript

In this article I am going to explain how to reverse a given value.
  • 1703

Array reverse method in JavaScript

One of the most useful array method of JavaScript , reverse() reverses the element of array, the first element of array become last element of array and last element of array become first element of array after the use of reverse method.

Syntax of array reverse method

array.reverse();


Revese method has no parameter.

Return value in reverse  method

It returned the reversed single value of the array.
 

Example of reverse method
 

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Array Reverse Method</title>
</head>
<body>
<script type="text/javascript">
   var val, rev;                
   val = new Array(1,2,3,4,5);
   rev = val.reverse();        
   document.write(rev);
</script>
</body>
</html>


Output:
 

5,4,3,2,1


Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2018 DotNetHeaven. All rights reserved.