Lodash _.pullAll() method

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

What you’ll learn

  • How _.pullAll(array, values) removes every element from array that appears in the values list.
  • Why this mirrors _.pull() but accepts a single array argument instead of a variadic list.
  • That the operation mutates array and returns the same reference, with SameValueZero matching rules.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Read _.pull() first for the same removal semantics with variadic arguments.

  • You understand that mutating an array every variable points at affects every observer of that reference.
  • You can run snippets in Node or open the Try-it labs in a browser.

Overview

_.pullAll is the array-driven twin of _.pull. Instead of listing values as separate parameters, you pass one array of forbidden values—often loaded from configuration or user input—and Lodash removes every matching slot from the target collection.

Ban list array

Keep removable IDs or tokens in one array and pass it wholesale.

In place

The first argument is mutated; the return value is the same reference.

All matches

Every duplicate of each banned value is removed, not only the first hit.

Syntax

javascript
_.pullAll(array, values)
  • array: collection to mutate (array-like values are coerced).
  • values: array of values to strip from array wherever they appear (SameValueZero).
  • Returns: the same array reference after removal.
1

Remove with a value array

The second argument lists everything to delete; order in the ban list does not matter.

javascript
import pullAll from "lodash/pullAll";

const nums = [1, 2, 3, 1, 2, 3];
pullAll(nums, [1, 3]);
// nums is now [2, 2]
Try it Yourself
2

Dynamic ban list

Reuse the same helper when the removable set is built at runtime—for example stripping sentinel values from telemetry.

javascript
import pullAll from "lodash/pullAll";

const scores = [10, 0, 5, null, 10];
const banned = [0, null];
pullAll(scores, banned);
// scores is now [10, 5, 10]
Try it Yourself
3

Object identity

The values array can hold references; only slots strictly equal to those references are removed.

javascript
import pullAll from "lodash/pullAll";

const marker = { id: 1 };
const rows = [marker, { id: 1 }, marker];
pullAll(rows, [marker]);
// rows is now [{ id: 1 }]
Try it Yourself

📋 _.pullAll vs _.pull vs spread

APIWhen to useNote
_.pullAll(array, values)Ban list already in an arrayNo manual ... spread of the list
_.pull(array, ...values)Fixed handful of literalsVariadic call mirrors other Lodash APIs
array.filter(x => !ban.has(x))Immutable copyLeaves array unchanged; allocate when you must not mutate

Pitfalls to avoid

Share

Shared references

Any holder of the same array reference sees the mutation immediately—clone before pullAll when you need an undo buffer.

Args

Wrong arity

pullAll expects the second argument to be the values array; accidentally passing bare primitives skips the intended removal list.

Deep

No deep equality

Objects still compare by reference; deep structures are not matched field-by-field.

❓ FAQ

Yes. Elements are removed in place and the same array reference is returned, just like _.pull.
pull takes individual values as extra arguments. pullAll takes one array argument that lists every value to strip—ideal when the list already exists as an array.
Duplicates in the ban list do not change the outcome; each distinct value is still removed everywhere it appears in the target array.
SameValueZero semantics match _.pull: NaN matches NaN, and +0 matches -0 for removal decisions.
Use import pullAll from "lodash/pullAll" or require("lodash/pullAll") for tree-shaking friendly bundles.

Summary

  • Purpose: _.pullAll(array, values) removes every occurrence of each entry in values from array using SameValueZero.
  • Shape: prefer this over variadic pull when the removable set is already stored as an array.
  • Next: Lodash _.pullAllBy(), _.pull() (earlier in this track), or the array methods hub.
Did you know?

When the ban list is already an array variable (for example from configuration), pullAll reads more cleanly than pull(array, ...list) with manual spreads.

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