JavaScript Array.pop() Method

Usage — The JavaScript Array.pop() method is used to remove the last element from an array and returns that element. This method changes the length of the array.

It has the following syntax:

arr.pop()

Here is an example of using Array.pop():

var fruits = ['Apple', 'Mango', 'Orange', 'Banana'];
var popped = fruits.pop();

// Output — Banana
console.log(popped);

// Output — ["Apple", "Mango", "Orange"]
console.log(fruits);

Return Value — This method returns the removed element from the array. It returns undefined if the array is empty.

Additional Information — This Array.pop() method is intentionally generic. This method can be called or applied to objects resembling arrays.

Keep in mind the objects which do not contain a length property reflecting the last in a series of consecutive, zero-based numerical properties may not behave in any meaningful manner.

Also remember that if you call pop() on an empty array, it returns undefined.

Browser Support — The Array.pop() method is available in Chrome, Edge, Firefox, Internet Explorer 5.5+, Opera and Safari.

Go Directly To — usage, parameters or working examples.

Parameters

The Array.pop() method does not accept any parameters.

Working Examples

Here are some examples of using the Array.pop() method:

var fruits = ['Apple', 'Mango', 'Orange', 'Banana'];
var popped = fruits.pop();

// Output — Banana
console.log(popped);

// Output — ["Apple", "Mango", "Orange"]
console.log(fruits);

Further Reading

  1. You can read more about the JavaScript Array.pop() method on MDN.
  2. You can also take a look at the defeinition of JavaScript Array.pop() method in the ECMAScript 2015 specification.

Reader Comments

1. You can register or login to post a comment. Asking readers to register improves the quality of discussion.

2. As a registered user, you will also get to access features like choosing between a light and dark theme or anything else that we might implement in future.

Follow Us For Updates

FacebookTwitterGoogle+
Go To Top