Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

pop Method

Removes the last element from an array and returns it.

function pop() : Object

The push and pop methods enable you to simulate a stack, which uses the principle of last in, first out (LIFO) to store data.

If the array is empty, undefined is returned.

The following example illustrates the use of the pop method.

var my_array = new Array();

my_array.push (5, 6, 7);
my_array.push (8, 9);

var s = "";
var number;

number = my_array.pop();
while (number != undefined)
    {
    s += number + " ";
    number = my_array.pop();
    }

print (s);
// Output: 9 8 7 6 5

Community Additions

ADD
Show:
© 2015 Microsoft