JavaScript Array reverse() method : The reverse() method is used to reverse the order of the array elements.
Syntax of Array reverse() method :
array.reverse()
Example of Array reverse() method : Here in the following example I will show you how to reverse the order of the elements in the array?
<!DOCTYPE html>
<html>
<body>
<p>To reverse the order of the elements in the array, click the button "reverse".</p>
<button onclick="reverseElements()">reverse</button>
<p id="container"></p>
<script>
function reverseElements() {
var students = ["Ashok", "Nitin Kumar", "Rajesh", "Pankaj", "Sumit", "Manish", "Pramod"];
var result = students.reverse();
document.getElementById("container").innerHTML = students;
}
</script>
</body>
</html>
Output :
Pramod,Manish,Sumit,Pankaj,Rajesh,Nitin Kumar,Ashok
0 Comment(s)