pop()

ES3+

Removes the last element from an array and returns that element.

Syntax

array.pop()

Return Value

any

The removed element, or undefined if empty

Examples

JavaScript
const fruits = ['apple', 'banana', 'cherry'];
const last = fruits.pop();
console.log(last);
console.log(fruits);
Output:
// 'cherry' ['apple', 'banana']

Related Methods