.pop()

Removes the last element of an array, decrements the array length, and returns the value that it removed.

Syntax

array.pop();

Examples

To pop the element 'sleep' from the schedule array:

const schedule = ['wake up', 'eat', 'work', 'play', 'sleep'];
const lastThingToDo = schedule.pop();
console.log(lastThingToDo);
// Output: sleep
console.log(schedule);
// Output: ['wake up', 'eat', 'work', 'play']
Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn JavaScript on Codecademy