JavaScript Array pop() method: The pop() method is used to remove the last element of the array. The pop() method returns the removed element. The pop() method changes the length of the array by decreasing one.
Syntax of Array pop() method :
array.pop()
Example of Array pop() method : In the following example I will show how to remove the last element of the array?
<!DOCTYPE html>
<html>
<body>
<p>To remove the last element of the array, click the button "remove last element".</p>
<button onclick="removeLastElement()">remove last element</button>
<p id="container"></p>
<script>
function removeLastElement() {
var students = ["Ashok", "Nitin Kumar", "Rajesh", "Pankaj", "Sumit", "Manish", "Rajesh", "Pramod"];
var result = students.pop();
document.getElementById("container").innerHTML = students;
}
</script>
</body>
</html>
Output :
Ashok, Nitin Kumar, Rajesh, Pankaj, Sumit, Manish, Rajesh
0 Comment(s)