The reverse method in JavaScript arrays alters the order of the elements within the specified array and provides the reversed arrangement. To put it differently, the final element of the array becomes the initial element, while the first element is shifted to the end. Additionally, this method modifies the original array as well.
Syntax
The syntax for the reverse method is expressed as follows:
array.reverse()
Return
The original array elements in reverse order.
JavaScript Array reverse method example
Let’s examine an example that demonstrates how to reverse the order of elements in an array.
Example
<script>
var arr=["AngulaJS","Node.js","JQuery"];
var rev=arr.reverse();
document.writeln(rev);
</script>
Output:
JQuery,Node.js,AngulaJS