Reverse array javascript

We use arrays in JavaScript to store multiple values. We can easily reverse an array using JavaScript by using reverse() method.

<!DOCTYPE html>
<html>
<body>
<p>Reverse Array JavaScript Example:</p>
<button onclick="reverseArrayValue()" id="btnClick">Click</button>
<p id="pId"></p>
<script>
var season = ["Summer", "Winter", "Monsoon","Spring"];
document.getElementById("pId").innerHTML = season;
function reverseArrayValue() {
season.reverse();
document.getElementById("pId").innerHTML = season;
}
</script>
</body>
</html>

We can able to see how the code is helpful to change the sequence of season.

Leave a Reply

Your email address will not be published. Required fields are marked *