A-C > Array (object)
Array (object)
The Array object allows you to access and manipulate arrays. An array is an object whose properties are identified by a number representing their position in the array. This number is sometimes referred to as the index. All arrays are zero based, which means that the first element in the array is [0], the second element is [1], and so on. In the following example, myArray
contains the months of the year, identified by number.
myArray[0] = "January"
myArray[1] = "February"
myArray[2] = "March"
myArray[3] = "April"
To create an Array object, use the constructor new Array
. To access the elements of an array use, the array access operator [ ].
Concatenates the arguments and returns them as a new array. Joins all elements of an array into a string. Removes the last element of an array, and returns its value. Adds one or more elements to the end of an array and returns the array's new length. Reverses the direction of an array. Removes the first element from an array, and returns its value. Extracts a section of an array and returns it as a new array. Sorts an array in place. Adds and/or removes elements from an array. Returns a string value representing the elements in the Array object. Adds one or more elements to the beginning of an array and returns the array's new length.
Method
Description
concat
join
pop
push
reverse
shift
slice
sort
splice
toString
unshift
Method summary for the Array object
Returns the length of the array.
Property summary for the Array object
Property
Description
length
Constructor for the Array object
Syntax
new Array();
new Array(
length
);
new Array(
element0, element1, element2,...elementN
);
Arguments
length
An integer specifying the number of elements in the array. In the case of noncontiguous elements, the length specifies the index number of the last element in the array plus 1. For more information, see the property Array.length
.
element0...elementN
A list of two or more arbitrary values. The values can be numbers, names, or other elements specified in an array. The first element in an array always has the index or position 0.
Description
Constructor; allows you to access and manipulate elements in an array. Arrays are zero based and the elements are indexed by their ordinal number.
If you don't specify any arguments, a zero-length array is created.
Player
Flash 5 or later.
Example
The following example creates a new Array object with an initial length of 0:
myArray
= new Array();
The following example creates the new Array object A-Team
, with an initial length of 4:
A-Team = new Array("Jody", "Mary", "Marcelle", "Judy");
The initial elements of the A-Team
array are as follows:
myArray[0] = "Jody"
myArray[1] = "Mary"
myArray[2] = "Marcelle"
myArray[3] = "Judy"
See also
Array.length