Lodash _.pullAt() method

Beginner
⏱️ 7 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.pullAt(array, indexes) deletes specific indexes and returns the removed values as a new array.
  • That the source array is still mutated in place (length changes, survivors shift).
  • How this differs from splice ergonomics and from value-based _.pull().
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Helpful context: _.nth() for index thinking and _.pullAllWith() for comparator-based removals.

  • You understand zero-based indexes and that removing an element shifts every higher index down by one.
  • You can run snippets in Node or open the Try-it labs in a browser.

Overview

_.pullAt is the surgical index remover: supply one or many indexes, Lodash strips those slots from the collection, and hands you a fresh array with exactly the removed elements. The original array keeps the survivors—just shorter.

By index

Target explicit positions instead of searching for values.

Removed chunk

Return value is the list of pulled-out elements, not the shortened array.

In place

The source array is mutated; clone first when you need a rollback copy.

Syntax

javascript
_.pullAt(array, [indexes])
  • array: collection to mutate (array-like values are coerced).
  • indexes: integers or nested arrays of integers; Lodash flattens extra argument layers.
  • Returns: a new array containing the removed elements (not the mutated array reference).
1

Multiple indexes

Pass an array of indexes; survivors compact while the return value collects the removed entries.

javascript
import pullAt from "lodash/pullAt";

const letters = ["a", "b", "c", "d"];
const removed = pullAt(letters, [1, 3]);
// removed is ["b", "d"]; letters is now ["a", "c"]
Try it Yourself
2

Variadic indexes

Indexes can be listed as additional arguments; Lodash normalizes them the same as a single flat array.

javascript
import pullAt from "lodash/pullAt";

const nums = [10, 20, 30, 40, 50];
const removed = pullAt(nums, 0, 2, 4);
// removed is [10, 30, 50]; nums is now [20, 40]
Try it Yourself
3

Single index

Removing one slot still returns an array of length one so call sites can always treat the result as a list.

javascript
import pullAt from "lodash/pullAt";

const queue = ["first", "second", "third"];
const removed = pullAt(queue, 1);
// removed is ["second"]; queue is now ["first", "third"]
Try it Yourself

📋 _.pullAt vs Array.prototype.splice vs _.pull

APIFocusNote
_.pullAt(array, indexes)Remove by index listReturns removed values; mutates array
splice(start, deleteCount, ...items)Window delete / insertReturns removed segment; can insert replacements at start
_.pull(array, ...values)Remove by valueReturns the mutated array reference, not a removed-values array

Pitfalls to avoid

Idx

Shifting indexes

After a removal, later indexes refer to different elements; compute index lists on a snapshot or remove from the highest index downward in your own loops.

Ret

Return shape

Do not assign the return value to the variable that should still point at the full collection—it is only the removed slice.

Copy

Shared arrays

Other modules holding the same reference see the mutation immediately—clone first when isolation matters.

❓ FAQ

Yes. Slots at the given indexes are removed in place, so length and neighboring indexes change. Lodash still returns a separate array containing the removed values.
An array of the removed elements in the order Lodash collected them—not the mutated source array. Capture that return value when you need the pulled values.
Yes. Lodash flattens index arguments, so pullAt(arr, 1, 2) and pullAt(arr, [1, 2]) are both valid shapes after normalization.
splice returns deleted items but uses (start, deleteCount, ...items) semantics and can insert replacements. pullAt only removes by explicit indexes and focuses on returning the pulled-out values.
Use import pullAt from "lodash/pullAt" or require("lodash/pullAt") for tree-shaking friendly bundles.

Summary

  • Purpose: _.pullAt(array, indexes) deletes the listed indexes and returns a new array of the removed elements.
  • Mutation: array is shortened in place; capture the return value when you need the pulled values.
  • Next: Lodash _.remove(), _.pullAllWith() (previous), or the array methods hub.
Did you know?

Unlike _.pull(), which returns the same shortened array reference, _.pullAt returns a new array containing only the elements that were spliced out—handy when you need both the survivors and the removed chunk.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful