at
The at() method returns the element at a given index (supports negative indexes).
Interactive example
Syntax
Classic signature
typescript
export function at<
GenericArray extends readonly unknown[],
GenericIndex extends number,
>(
array: GenericArray,
index: GenericIndex,
): AtArray<GenericArray, GenericIndex>Curried signature
typescript
export function at<
GenericArray extends readonly unknown[],
GenericIndex extends number,
>(
index: GenericIndex,
): (array: GenericArray) => AtArray<GenericArray, GenericIndex>Parameters
input: The array from which to retrieve an element.index: The index of the element to retrieve (can be negative to count from the end).
Return value
The element at the given index, or undefined if the index is out of bounds.
