Home >>JavaScript Array Reference >JavaScript Array pop() Method

JavaScript Array pop() Method

JavaScript Array pop() Method

JavaScript array pop() methodis used to remove the last element from an array and returns the removed element and also changes the length of an array.

Syntax:
array.pop()

Browser Support

Method Chrome Edge Firefox Safari Opera
pop() 1.0 5.5 1.0 Yes Yes
Here is an example of array pop() method:
<html>
<body>
<button onclick="myPop()">click me</button>
<p id="POP"></p>
<script>
var y = ["Red", "Blue", "Green", "Yellow"];
document.getElementById("POP").innerHTML = y;
function myPop()
{
  y.pop();
  document.getElementById("POP").innerHTML = y;
}
</script>
</body>
</html>
Output:

Example 2:
<html>
<body>
<script> 
function popmethod()
{ 
  var z = []; 
  var popped = z.pop(); 
  document.write(popped); 
} 
popmethod(); 
</script> 
</body>
</html>
Output:

No Sidebar ads