Array.prototype.pop
Removes the last element from an array and returns that element, changing the length of the array
Syntax
array.pop()Return Value
The removed element, or undefined if the array is empty
Examples
const plants = ['broccoli', 'cauliflower', 'kale'];
const last = plants.pop();
console.log(last); // 'kale'
console.log(plants); // ['broccoli', 'cauliflower']const stack = [1, 2, 3];
while (stack.length) {
console.log(stack.pop());
}
// 3, 2, 1const arr: number[] = [];
console.log(arr.pop()); // undefinedUnderstanding 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
Array.prototype.pushAdds the specified elements to the end of an array and returns the new length of the array
Array.prototype.shiftRemoves the first element from an array and returns that removed element, changing the length of the array
Array.prototype.spliceChanges the contents of an array by removing or replacing existing elements and/or adding new elements in place
Array.prototype.atTakes an integer value and returns the item at that index, allowing for positive and negative integers where negative integers count back from the last item
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.