Lodash _.pull() method

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

What you’ll learn

  • How _.pull(array, ...values) deletes all matching elements from the existing array.
  • That the method mutates the array and returns the same reference (unlike filter-based copies).
  • How SameValueZero affects primitives such as NaN and how object identity affects removals.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Read _.nth() for non-destructive reads; skim _.fill() for another in-place Lodash array API.

  • 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

_.pull is the variadic “strip these exact values out” helper. It walks the array, drops every slot that matches any argument (SameValueZero), compacts the tail, and returns the mutated array so you can chain or reassign confidently.

In place

The original binding changes length and contents; no new array is allocated for the removal pass.

All matches

Every duplicate of each supplied value disappears, not only the first hit.

Variadic values

List values as additional arguments; use pullAll when you already hold an array of values to remove.

Syntax

javascript
_.pull(array, [values...])
  • array: collection to mutate (array-like values are coerced).
  • values: any number of extra arguments; each unique value is removed everywhere it appears.
  • Returns: the same array reference after removal.
1

Remove primitives

Pass the values to strip; the array shrinks in place and the returned reference equals the input binding.

javascript
import pull from "lodash/pull";

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

Remove NaN

SameValueZero treats NaN as equal to itself, so pull can clear noisy placeholders that indexOf historically struggled with.

javascript
import pull from "lodash/pull";

const readings = [NaN, 1, NaN];
pull(readings, NaN);
// readings is now [1]
Try it Yourself
3

Object identity

Objects match only by reference; a fresh literal is never equal to a different literal, even with identical fields.

javascript
import pull from "lodash/pull";

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

📋 _.pull vs _.pullAll vs immutable filtering

APIInput styleNote
_.pull(array, a, b, c)Variadic valuesMutates array; removes every match for each argument
_.pullAll(array, [a, b, c])Array of valuesSame mutation semantics when the list already lives in an array
array.filter(x => !values.has(x))Predicate / setReturns a new array; keeps the original untouched

Pitfalls to avoid

Share

Hidden aliasing

If another module holds the same array reference, your pull changes its data too—clone first when isolation matters.

Copy

Expecting a new array

Use slice(), spread, or filter when you must preserve the old snapshot for comparison or undo flows.

Deep

No deep matching

Nested objects are not compared by structure; only references and primitive SameValueZero rules apply.

❓ FAQ

Yes. Lodash removes matching elements in place and returns the same array reference. Clone first (for example with slice or structuredClone for deep copies) if other code still needs the old contents.
SameValueZero semantics align with indexOf-style searches: NaN matches NaN, and +0 matches -0 for removal decisions.
pull accepts individual values as separate arguments after the array. pullAll accepts a single array argument listing every value to strip out.
No. Every slot that matches any provided value is removed, which can shrink the array by more than one index.
Use import pull from "lodash/pull" or require("lodash/pull") for tree-shaking friendly bundles.

Summary

  • Purpose: _.pull(array, ...values) removes every occurrence of each supplied value using SameValueZero and returns the mutated array.
  • Mutation: prefer filter / slice patterns when callers must keep the previous contents.
  • Next: Lodash _.pullAll(), _.nth() (earlier in this track), or the array methods hub.
Did you know?

Like _.fill(), _.pull mutates the array and returns the same reference so callers can keep using the original binding or chain further Lodash calls.

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