Section 24.10. Array.pop( ): remove and return the last element of an array


24.10. Array.pop( ): remove and return the last element of an array

ECMAScript v3

24.10.1. Synopsis

 array.pop( ) 

24.10.1.1. Returns

The last element of array.

24.10.2. Description

pop( ) deletes the last element of array, decrements the array length, and returns the value of the element that it deleted. If the array is already empty, pop( ) does not change the array and returns the undefined value.

24.10.3. Example

pop( ), and its companion method push( ), provide the functionality of a first-in, last-out stack. For example:

 var stack = [];       // stack: [] stack.push(1, 2);     // stack: [1,2]     Returns 2 stack.pop( );            // stack: [1]       Returns 2 stack.push([4,5]);      // stack: [1,[4,5]] Returns 2 stack.pop( )             // stack: [1]       Returns [4,5] stack.pop( );            // stack: []        Returns 1 

24.10.4. See Also

Array.push( )




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net