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/pullAt.md.

pullAt es-toolkit

Removes elements at specified indices from an array and returns the removed elements.

const removed = pullAt(arr, indices);

Usage

pullAt(arr, indicesToRemove)

Use pullAt when you want to remove elements at specific positions in an array. This function modifies the original array and returns the removed elements in a new array. It also supports negative indices, which count from the end of the array.

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

// Remove elements at multiple indices at once.
const numbers = [10, 20, 30, 40, 50];
const removed = pullAt(numbers, [1, 3, 4]);
console.log(removed); // [20, 40, 50]
console.log(numbers); // [10, 30]

// Safely handle duplicate indices.
const fruits = ['apple', 'banana', 'cherry', 'date'];
const removedFruits = pullAt(fruits, [1, 2, 1]);
console.log(removedFruits); // ['banana', 'cherry', 'banana']
console.log(fruits); // ['apple', 'date']

If you specify a non-existent index, undefined is returned for that position.

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

const items = [1, 2, 3];
const removed = pullAt(items, [0, 5, 2]);
console.log(removed); // [1, undefined, 3]
console.log(items); // [2]

Parameters

arrT[]required

The array from which to remove elements.

indicesToRemovereadonly number[]required

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

Returns

A new array containing the removed elements. For non-existent indices, undefined is included.

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.