For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/array/at.md.

at es-toolkit

Gets the elements at specified indices from an array and returns a new array.

const result = at(arr, indices);

Reference

at(arr, indices)

Use at when you want to select elements at specific positions from an array. You can use negative indices to select elements from the end of the array.

import { at } from 'es-toolkit/array';

// Get elements at multiple indices from a number array.
at([10, 20, 30, 40, 50], [1, 3, 4]);
// Returns: [20, 40, 50]

// Use negative indices to get elements from the end.
at(['a', 'b', 'c', 'd'], [0, -1, -2]);
// Returns: ['a', 'd', 'c']

Non-integer indices are converted to integers.

import { at } from 'es-toolkit/array';

at([1, 2, 3, 4], [1.5, 2.9]); // [2, 3]

Parameters

arrreadonly T[]required

The array to get elements from.

indicesreadonly number[]required

An array of indices of the elements to get. Negative values count from the end of the array.

Returns

A new array containing the elements at the specified indices.

T[]
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.