class array

This is the built-in array class.

JewelScript arrays can dynamically grow depending on the index used to access elements from it. In general, setting an array element with an index that is out of range, will cause the array to grow to the required number of elements. Getting an array index with an index that is out of range will NOT resize the array, but return null instead. So one should be cautious to not use invalid array indices. The array index is a signed 32-bit value, so an array is limited to about 2 billion elements. Operator += can be used to add new elements to an array, as well as append an array to an array.

Constructors

array ()Creates a new, empty array.

Convertors

string convertor ()Recursively converts all convertible elements of this array into a string.

Methods

var[] deepCopy ()Recursively creates a deep-copy of this array.
enumerate (array::enumerator, var)Calls a delegate for every element in this array.
string format (const string)Formats this array into a string.
int indexOf (var, const int)Searches 'item' in a one-dimensional array and returns the index of the first occurrence.
var[] insert (const var[], const int)Inserts the specified array into this array at the given index.
var[] insertItem (var, const int)Inserts the specified element into this array at the given index.
var pop ()Removes the top level element from this array and returns it.
var[] process (array::processor, var)Calls a delegate for every element in this array.
push (var)Adds the specified item to the end of this array.
var[] remove (const int, const int)Removes the specified range of elements from this array and returns the result as a new array.
var[] sort (array::comparator)Sorts this array's elements depending on the specified comparator delegate.
var[] subArray (const int, const int)Returns the specified range of elements from this array as a new array.
swap (const int, const int)Exchanges the positions of the specified elements in the array.
string toString ()Recursively converts all convertible elements of this array into a string.

Properties

int length ()Returns the length of this array in elements.
var top ()Returns the reference of the top level element in this array.

Reference

method array ()

Creates a new, empty array.


explicit method string convertor ()

Recursively converts all convertible elements of this array into a string.

This method can be slow for very complex multi-dimensional arrays, so an explicit type cast is required to confirm that the conversion is really wanted.


method var[] deepCopy ()

Recursively creates a deep-copy of this array.

WARNING: All element data will be copied! If the array is multi-dimensional and / or contains script objects that have copy-constructors, this method can be very time consuming. It should only be called in cases where a shallow-copy would not suffice.


method enumerate (array::enumerator fn, var args)

Calls a delegate for every element in this array.


method string format (const string format)

Formats this array into a string.

The format string must contain ANSI format identifiers. Every subsequent identifier in the format string is associated with the next array element. This only works with one dimensional arrays.


method int indexOf (var item, const int index)

Searches 'item' in a one-dimensional array and returns the index of the first occurrence.

The search starts at the given 'index' position. Integers, floats and strings will be compared by value, all other types will be compared by reference. If no element is found, -1 is returned.


method var[] insert (const var[] src, const int index)

Inserts the specified array into this array at the given index.

The result will be returned as a new array.


method var[] insertItem (var item, const int index)

Inserts the specified element into this array at the given index.

The result will be returned as a new array.


method var pop ()

Removes the top level element from this array and returns it.

If the array is currently empty, null is returned. This actually modifies the array and allows to use it like a stack.


method var[] process (array::processor fn, var args)

Calls a delegate for every element in this array.

The delegate may process the element and return it. It may also return null. The function will concatenate all non-null results of the delegate into a new array.


method push (var item)

Adds the specified item to the end of this array.

This actually modifies the array and allows to use it like a stack.


method var[] remove (const int index, const int length)

Removes the specified range of elements from this array and returns the result as a new array.


method var[] sort (array::comparator fn)

Sorts this array's elements depending on the specified comparator delegate.


method var[] subArray (const int index, const int length)

Returns the specified range of elements from this array as a new array.


method swap (const int index1, const int index2)

Exchanges the positions of the specified elements in the array.


method string toString ()

Recursively converts all convertible elements of this array into a string.

This method can be slow for very complex multi-dimensional arrays.


accessor int length ()

Returns the length of this array in elements.


accessor var top ()

Returns the reference of the top level element in this array.

The top level element is the element with the highest index. The operation is A[A.length - 1]. If the array is empty, this method will return null. If this array is multi-dimensional, this may return a sub-array.