Array.at
Array.at
Function
Read array elements by subscript, and support negative numbers in reverse reading from the end of the array.
Syntax
array.at(index)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| index | Int | No | 0 | Element index; negative numbers count backwards from the end. |
Return value
| Type | Description |
|---|---|
| Any/Empty | The corresponding element is returned when the subscript is valid, and Empty is returned when it is out of bounds. |
Example
items = ['a', 'b', 'c'] result = items.at(-1) // Output: c print result
Notes
- at does not modify the original array.
- when reading the last element, at(-1) requires one less array allocation than slice(-1)[0].