The reverse() method of JavaScript is used to reverse the array elements.
The syntax is as follows −
array.reverse()
Let us now implement the reverse() method in JavaScript −
Example
<!DOCTYPE html>
<html>
<body>
<h2>Demo Heading</h2>
<p id="test"></p>
<script>
var arrStud = ["Laptop", "Desktop", "Tablet"];
document.getElementById("test").innerHTML = "Initial array = "+arrStud+", <br>Reversed array = "+arrStud.reverse();
</script>
</body>Output

Example
<!DOCTYPE html>
<html>
<body>
<h2>Car Variant</h2>
<button onclick="display()">Reverse</button>
<p id="test"></p>
<script>
var car = ["Hatchback", "Convertible", "SUV", "AUV", "MUV"];
document.getElementById("test").innerHTML = "Initial Array = "+car;
function display() {
car.reverse();
document.getElementById("test").innerHTML = "Reversed Array = "+car;
}
</script>
</body>Output

Click on “Reverse” button above −
