The Array object is used to store a set of values in a single variable name. Arrays are zero indexed meaning the first element is at index zero. Elements in arrays can be different types. The array elements are accessed through computed indexes. Square brackets [...] are used in the script to enclose the index number.
Constructors
Array ( )
Initializes a new empty
Array instance.
Syntax:Array ( )
Example:
a = new Array();
Instance Properties
BoundsLength
Gets the number of items from the lowest index to the highest index in the array. Empty indexes are included.
Accessibility : Read Only
Type:
NumberCanRead
Gets a value indicating whether the ScriptArray elements can be written to.
Accessibility : Read Only
Type:
BooleanCanWrite
Gets a value indicating whether the ScriptArray elements can be read.
Accessibility : Read Only
Type:
BooleanLength
Gets the total length of the array from index 0 to the last element.
Accessibility : Read Only
Type:
NumberLowestIndex
Gets the lowest index that has been assigned a value. Returns -1 if no array elements have been set.
Accessibility : Read Only
Type:
NumberHighestIndex
Gets the highest index that has been assigned a value. Returns -1 if no array elements have been set.
Accessibility : Read Only
Type:
NumberInstance Methods
Add
Adds an item to the array. If the array is empty then the item will be added at index zero. Returns the position into which the new element was inserted.
Syntax:Parameters:value: The item to add to the array.
Return ValueThe position into which the new element was inserted.
Example:
a = new Array();
index = a.Add("Hello"); // results in 0
index = a.Add("Bye"); // results in 1
Clear
Removes all items from the array.
Syntax:Parameters:none
Return Valuenone
Example:
a = new Array();
index = a.Add("Hello"); // results in 0
index = a.Add("Bye"); // results in 1
a.Clear(); // clears the array
Contains
Determines whether the array contains a specific value.
Syntax:Parameters:value: The item to locate in the array.
Return Valuetrue if the array contains the value, otherwise false.
Example:
a = new Array();
index = a.Add("Hello"); // results in 0
index = a.Add("Bye"); // results in 1
b = a.Contains("Bye"); // results in true
IndexOf
Determines the index of a specific item in the array. Returns the index of value if found in the list; otherwise, -1.
Syntax:Parameters:value: The item to locate in the array.
Return ValueThe index of value if found in the list; otherwise, -1.
Example:
a = new Array();
index = a.Add("Hello"); // results in 0
index = a.Add("Bye"); // results in 1
b = a.IndexOf("Bye"); // results in 1
Insert
Inserts an item to the array at the specified index.
Syntax:Parameters:index: The zero-based index at which value should be inserted.
value: The item to insert into the array.
Return Valuenone
Example:
a = new Array();
index = a.Add("Hello"); // results in 0
index = a.Add("Bye"); // results in 1
a.Insert(1, "Between");
Remove
Removes the first occurrence of a specific object from the array.
Syntax:Parameters:value: The object to remove from the array.
Return Valuenone
Example:
a = new Array();
index = a.Add("Hello"); // results in 0
index = a.Add("Bye"); // results in 1
a.Remove("Hello");
RemoveAt
Removes the item at the specified index from the array.
Syntax:Parameters:index: The zero-based index of the item to remove.
Return Valuenone
Example:
a = new Array();
index = a.Add("Hello"); // results in 0
index = a.Add("Bye"); // results in 1
a.RemoveAt(1);
Examples
a = new Array();
a[0] = 12;
a[1] = "one foot";
a[2] = 2.54 * 12;
x = a[1];