|
 |
You can use the Array object to create arrays in script. An array is an indexed data structure for storing information of related type in script.
Constructor
[new] Array() |
Creates and returns a new Array object of length 0. |
[new] Array(size) |
Creates
and returns a new Array object of length size. |
[new] Array(element0, element1,…,elementn) |
Creates and returns an Array object of length n. The elements of the array are specified by the supplied arguments element0, element1,...,elementn. String arguments must be quoted.
|
|
Instance Properties
length |
The number of elements in the array. |
|
Instance Methods
concat |
Forms a new array by adding elements to the calling array.
|
join |
Concatenates the elements of an array to form a single string. |
pop |
Removes and returns the last element in the calling array. |
push |
Adds elements to the end of the calling array. |
reverse |
Reverses the order of elements in the calling array. |
shift |
Removes and returns the first element of the calling array. |
slice |
Returns a portion of the calling array. |
splice |
Removes and/or replaces elements in the calling array. |
sort |
Sorts
the elements of the calling array. |
toString |
Converts the elements of an array to a single string. |
unshift |
Inserts
elements to the beginning of
the calling array
|
|
Example
The following examples demonstrate three uses of the Array object constructor.
//Creates a new array, Arr1.
//Arr1 is an empty array.
var Arr1 = new Array();
//Creates a new array, Arr2.
//Arr2 is an empty array,
//but it has memory to hold five elements.
var Arr2 = new Array(5);
//Creates a new array, Arr3.
//Arr3 contains three string elements.
var arr3 = new Array("Mercury", "Venus", "Earth");
|