Codecore Logo
Quick Search
»
Advanced Search »

Array Data Type

RSS
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: Number

CanRead

Gets a value indicating whether the ScriptArray elements can be written to.

Accessibility : Read Only

Type: Boolean

CanWrite

Gets a value indicating whether the ScriptArray elements can be read.

Accessibility : Read Only

Type: Boolean

Length

Gets the total length of the array from index 0 to the last element.

Accessibility : Read Only

Type: Number

LowestIndex

Gets the lowest index that has been assigned a value. Returns -1 if no array elements have been set.

Accessibility : Read Only

Type: Number

HighestIndex

Gets the highest index that has been assigned a value. Returns -1 if no array elements have been set.

Accessibility : Read Only

Type: Number

Instance 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:

Number Add(Object value)

Parameters:

value: The item to add to the array.

Return Value

The 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:

void Clear( )

Parameters:

none

Return Value

none

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:

Boolean Contains(Object value)

Parameters:

value: The item to locate in the array.

Return Value

true 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:

Number IndexOf(Object value)

Parameters:

value: The item to locate in the array.

Return Value

The 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:

void Insert(Number index, Object value)

Parameters:

index: The zero-based index at which value should be inserted.
value: The item to insert into the array.

Return Value

none

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:

void Remove(Object value)

Parameters:

value: The object to remove from the array.

Return Value

none

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:

void RemoveAt(Number Number)

Parameters:

index: The zero-based index of the item to remove.

Return Value

none

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];
Privacy Policy | Conditions Of Use

Copyright ©2014 Codecore Technologies, All rights reserved.