myArray.pop() in ECMAScript 262
Remove the last element from the array and return it.
- Return Type
- Object
Description
This method modifies the array which calls it.
Along with
push()
, this method allows arrays to be used as a 'stack' or 'FILO' object. The following code illustrates the push()
and pop()
methods in use.
var thingsToDo=[];
thingsToDo.push('TheLaundry');
thingsToDo.push('TheDishes');
thingsToDo.push('PlayVideoGames');
thingsToDo.length == 3; //true
thingsToDo.toString() == "TheLaundry,TheDishes,PlayVideoGames"; //true
var mostRecentAddition = thingsToDo.pop();
mostRecentAddition == "PlayVideoGames"; //true
thingsToDo.length == 2; //true--pop() removed the item
thingsToDo.toString() == "TheLaundry,TheDishes"; //true