at method
The at() method is equivalent to the bracket notation when index
is non-negative.
For example, array0
and array.at(0) both return the first item.
However, when counting elements from the end of the array, you cannot use
array-1
like you may in Python or R, because all values inside the square
brackets are treated literally as string properties, so you will end up
reading array"-1"
, which is just a normal string property instead of
an array index.
The usual practice is to access length and calculate the index from
that — for example, arrayarray.length - 1
.
The at() method allows relative indexing, so this can be shortened
to array.at(-1).
The at() method is generic. It only expects the this value to have a length property and integer-keyed properties.
Implementation
E? at(int index) => jsu.callMethod(this, 'at', [index]);