The Wayback Machine - https://web.archive.org/web/20220625080234/https://www.geeksforgeeks.org/javascript-array-pop-method/amp/

JavaScript Array pop() Method

Below is the example of Array pop() method.

The arr.pop() method is used to remove the last element of the array and also returns the removed element. This function decreases the length of the array by 1.

Syntax:

arr.pop()

Parameters: This method does not accept any parameter.

Return value This method returns the removed element array. If the array is empty, then this function returns undefined.



Below examples illustrate the JavaScript Array pop() method:

More example codes for the above method are as follows:

Program 1:




<script>
function func() {
    var arr = [34, 234, 567, 4];
  
    // Popping the last element from the array 
    var popped = arr.pop();
    document.write(popped);
    document.write("<br>");
    document.write(arr);
}
func();
</script>

Output:

4
34,234,567

Program 2:




<script>
function func() {
  
    var arr = [];
  
    // popping the last element
    var popped = arr.pop();
    document.write(popped);
}
func();
</script>

Output:

undefined

Supported Browsers: The browsers supported by JavaScript Array pop() method are listed below:




Article Tags :