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.
Creates an empty array.
| Item | Description |
|---|---|
| Syntax | `array()` |
| Arguments | none |
| Returns | array object |
Example:
items = array(); items.empty(); // true
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
`array` has no object-specific properties.
Use methods such as `get(index)`, `set(index, value)`, `size()`, and `join(separator)` to work with array contents.
Returns a display string for the object.
| Item | Description |
|---|---|
| Syntax | `value.to_string()` |
| Arguments | none |
| Returns | string |
Example:
text = value.to_string();
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();
Returns the number of values in the array.
| Item | Description |
|---|---|
| Syntax | `array.size()` |
| Arguments | none |
| Returns | number |
Example:
array(10, 20, 30).size(); // 3
Alias for `size()`.
| Item | Description |
|---|---|
| Syntax | `array.count()` |
| Arguments | none |
| Returns | number |
Example:
array('A', 'B').count(); // 2
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
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
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"]
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
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"]
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"]
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"]
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
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
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