.pop()

codewithfan5 total contributions
Published Jun 18, 2021Updated Jun 1, 2023
Contribute to Docs
Removes the last element of an array, decrements the array length, and returns the value that it removed.
Syntax
array.pop();
Example
To pop the element 'sleep'
from the schedule
array:
const schedule = ['wake up', 'eat', 'work', 'play', 'sleep'];const lastThingToDo = schedule.pop();console.log(lastThingToDo);console.log(schedule);
This results in the following output:
sleep['wake up', 'eat', 'work', 'play']
Codebyte Example
The following example below uses .pop()
on an array, flavor
, to remove the last element.
All contributors
- codewithfan5 total contributions
- christian.dinh2481 total contributions
- Anonymous contributorAnonymous contributor3077 total contributions
- Anonymous contributorAnonymous contributor92 total contributions
- codewithfan
- christian.dinh
- Anonymous contributor
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.