mutation

Array.prototype.pop

Removes the last element from the array and returns it (or undefined if empty). Reach for it to consume the tail of a list — the natural pair to push for stack behavior.

arr.pop()

Parameters

Parameter Purpose
(no parameters) Takes no arguments
return value The removed element, or undefined if the array was empty

Examples

const a = [1, 2, 3]; console.log(a.pop());

Logs: 3

const a = [1, 2, 3]; a.pop(); console.log(a);

Logs: [1, 2]

console.log([].pop());

Logs: undefined

const stack = []; stack.push(1); stack.push(2); console.log(stack.pop(), stack.pop());

Logs: 2 1 (LIFO)

Gotcha

MUTATES the source. Returns undefined on empty arrays — don't confuse an empty-array pop with a stored undefined value.

Related methods

← All JS array methods · TypeScript vs JavaScript