Table of Contents

array

An array is an ordered list of Expr values.

Create an array with `array(…)`.

items = array();
values = array(10, 20, 30);

Array indexes are zero-based.

Constructor

array()

Creates an empty array.

Item Description
Syntax `array()`
Arguments none
Returns array object

Example:

items = array();
items.empty();        // true

array(value, ...)

Creates an array initialized with the provided values.

Argument Type Description
`value` any First value.
`…` any Additional values.

Returns: array object.

Example:

items = array('A', 'B', 'C');
items.size();         // 3

Properties

`array` has no object-specific properties.

Use methods such as `get(index)`, `set(index, value)`, `size()`, and `join(separator)` to work with array contents.


Common Object Methods

to_string()

Returns a display string for the object.

Item Description
Syntax `value.to_string()`
Arguments none
Returns string

Example:

text = value.to_string();

clone()

Returns a new array object with the same values.

Item Description
Syntax `array.clone()`
Arguments none
Returns array object

Example:

items = array(1, 2, 3);
copy = items.clone();

Methods

size()

Returns the number of values in the array.

Item Description
Syntax `array.size()`
Arguments none
Returns number

Example:

array(10, 20, 30).size();      // 3

count()

Alias for `size()`.

Item Description
Syntax `array.count()`
Arguments none
Returns number

Example:

array('A', 'B').count();       // 2

empty()

Returns true when the array has no values.

Item Description
Syntax `array.empty()`
Arguments none
Returns boolean-style number

Example:

items = array();
items.empty();                 // true

clear()

Removes all values from the array.

Item Description
Syntax `array.clear()`
Arguments none
Returns boolean-style number

Example:

items = array(1, 2, 3);
items.clear();
items.size();                  // 0

add(value)

Appends a value to the end of the array.

Argument Type Description
`value` any Value to append.

Returns: boolean-style number.

Example:

items = array();
items.add('A');
items.add('B');
items.to_string();             // ["A", "B"]

get(index)

Returns the value at an index.

Argument Type Description
`index` number Zero-based index. Negative indexes are treated as `0`.

Returns: value at index, or `none()` when index is outside the array.

Example:

items = array('A', 'B');
items.get(0);                  // 'A'
items.get(9).is_none();        // true

set(index, value)

Sets a value at an index.

Argument Type Description
`index` number Zero-based index. Negative indexes are treated as `0`.
`value` any Value to store.

Returns: boolean-style number.

If the index is beyond the end of the array, the array grows and missing entries are filled with `none()`.

Example:

items = array('A');
items.set(2, 'C');
items.to_string();             // ["A", none, "C"]

insert(index, value)

Inserts a value before an index.

Argument Type Description
`index` number Zero-based index. Negative indexes are treated as `0`. Values beyond the end insert at the end.
`value` any Value to insert.

Returns: boolean-style number.

Example:

items = array('A', 'C');
items.insert(1, 'B');
items.to_string();             // ["A", "B", "C"]

remove(index)

Removes the value at an index.

Argument Type Description
`index` number Zero-based index. Negative indexes are treated as `0`.

Returns: true if a value was removed, false when index is outside the array.

Example:

items = array('A', 'B', 'C');
items.remove(1);
items.to_string();             // ["A", "C"]

find(value)

Finds the first matching value.

Argument Type Description
`value` any Value to find.

Returns: zero-based index, or `-1` when not found.

Example:

items = array('A', 'B', 'C');
items.find('B');               // 1
items.find('X');               // -1

find(value, startIndex)

Finds the first matching value at or after `startIndex`.

Argument Type Description
`value` any Value to find.
`startIndex` number Zero-based start index. Negative indexes are treated as `0`.

Returns: zero-based index, or `-1` when not found.

Example:

items = array('A', 'B', 'A');
items.find('A', 1);            // 2

join(separator)

Converts array values to strings and joins them with a separator.

Argument Type Description
`separator` any Separator text.

Returns: string.

Example:

items = array('A', 'B', 'C');
items.join(',');               // 'A,B,C'

Previous: Collections

Next: map