This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

pop

Summary

Removes the last element from an array and returns it.

Syntax

pop( )

Examples

The following example illustrates the use of the pop method.

var number;
 var my_array = new Array();

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

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

 // Output: 9 8 7 6 5

Remarks

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

The required arrayObj reference is an Array object.

If the array is empty, undefined is returned.

See also

Specification

15.4.4.6 Array.prototype.pop ( ) ECMAScript® Language Specification Standard ECMA-262 5.1 Edition / June 2011

Attributions

  • Microsoft Developer Network: Article