Array.prototype.pop()
Overview.
The Array.prototype.pop()
method removes the last element from an array and returns that element. This method changes the length of the array.
Syntax
array.pop();
Parameters
No parameter.
return value
The removed element from the array, or undefined
if the array is empty.
Examples
const fruits = ["apple", "banana", "orange"];
const lastFruit = fruits.pop();
// lastFruit is "orange"
// fruits is now ["apple", "banana"]
Notes
- The
pop()
method modifies the original array. - If the array is empty,
pop()
returnsundefined
. - It is possible to use
pop()
together withpush()
to implement a basic stack data structure.
This page was updated on -
Found an error or have feedback on our docs?
Create an issue on GitHub and let us know! Your input helps improve our documentation for everyone in the community.
Report error, send feedback on Github