Array

Array.prototype.pop

Removes the last element from an array and returns that element, changing the length of the array

Syntax

JavaScript
array.pop()

Return Value

The removed element, or undefined if the array is empty

Examples

Basic Usage
const plants = ['broccoli', 'cauliflower', 'kale'];
const last = plants.pop();
console.log(last); // 'kale'
console.log(plants); // ['broccoli', 'cauliflower']
Practical Example
const stack = [1, 2, 3];
while (stack.length) {
  console.log(stack.pop());
}
// 3, 2, 1
Advanced Usage
const arr: number[] = [];
console.log(arr.pop()); // undefined

Understanding Array.prototype.pop

The Array.prototype.pop method in JavaScript removes the last element from an array and returns that element, changing the length of the array. It belongs to the Array object and is one of the most widely used methods for working with array values in modern JavaScript and TypeScript applications.

The method signature is array.pop(). When called, it returns the removed element, or undefined if the array is empty. Understanding when and how to use pop() helps you write more expressive, readable code.

Common use cases for Array.prototype.pop include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like array-push, array-shift, array-splice, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Array.prototype.pop is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Array Methods

Other methods in the Array object

Related Tools

More Array Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.