.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: sleepconsole.log(schedule);// Output: ['wake up', 'eat', 'work', 'play']
Contributors
- Anonymous contributors