reverse()

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:

Example

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

Example

<script>

var arr=["AngulaJS","Node.js","JQuery"];

var rev=arr.reverse();

document.writeln(rev);

</script>

Output:

Output

JQuery,Node.js,AngulaJS

Input Required

This code uses input(). Please provide values below: