Name

Array.unshift( ) Method — add one or more elements to the beginning of an array

Availability

Flash 5

Synopsis

array.unshift(value1, value2,...valuen)

Arguments

value1,...valuen

A list of one or more element values to be added to the beginning of array.

Returns

The new length of array.

Description

The unshift( ) method adds a series of elements to the beginning of an array. Elements are added in the order specified. To add elements at the end of an array, use push( ) .

Example

myList = new Array (5, 6);
myList.unshift(4);         // myList becomes [4, 5, 6]
myList.unshift(7, 1);      // myList becomes [7, 1, 4, 5, 6]

See Also

Array.push( ), Array.shift( ); Section 11.7 in Chapter 11

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.