at
The at() method returns the element at a given index (supports negative indexes).
Interactive example
Syntax
Classic signature
typescript
function at<
GenericInputTuple extends readonly unknown[],
GenericIndex extends number
>(
input: GenericInputTuple,
index: GenericIndex
): AtTuple<GenericInputTuple, GenericIndex>
function at<
GenericElement extends unknown
>(
input: readonly GenericElement[],
index: number
): GenericElement | undefinedCurried signature
typescript
function at<
GenericInputTuple extends readonly unknown[],
GenericIndex extends number
>(
index: GenericIndex
): (input: GenericInputTuple) => AtTuple<GenericInputTuple, GenericIndex>
function at<
GenericElement extends unknown
>(
index: number
): (input: readonly GenericElement[]) => GenericElement | undefinedParameters
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.
