Name

Array.pop( ) Method — remove the last element of an array

Availability

Flash 5

Synopsis

array.pop( )

Returns

The value of the last element of array, which is also deleted.

Description

The pop( ) method deletes the last element of an array, reduces the array’s length by 1, and returns the value of the deleted element. Compare with the shift( ) method, which deletes the first element of an array.

Example

myList = new Array("one", "two", "three");
trace ("Now deleting " + myList.pop( ));  // myList is now: ["one", "two"]

See Also

Array.push( ), Array.shift( ), Array.splice( ); “Removing Elements from an Array” in Chapter 11, “The delete Operator” in Chapter 5

Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.