Lodash _.pullAllWith() method

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

What you’ll learn

  • How _.pullAllWith(array, values, comparator) deletes elements when comparator(arrVal, othVal) is truthy for any othVal in values.
  • Why this generalizes _.pullAllBy() when pairwise logic beats a single projection.
  • How to pair the helper with _.isEqual for nested structures and when to clone first.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Read _.pullAllBy() and _.intersectionWith() for comparator conventions; optional _.differenceWith() for non-mutating subtraction.

  • You understand that in-place array helpers affect every reference to that array.
  • You can run snippets in Node or open the Try-it labs in a browser.

Overview

_.pullAllWith is the comparator-driven removal tool in the pull family. Lodash asks your function to decide whether an element from the target array “matches” any ban entry; truthy answers drop the element, while the array reference itself is preserved for chaining.

Pairwise control

Compare arrVal and othVal directly instead of projecting through one iteratee.

In place

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

Deep equals

Reuse _.isEqual when nested shapes must match, not just top-level references.

Syntax

javascript
_.pullAllWith(array, values, [comparator])
  • array: collection to mutate.
  • values: array of exclusion candidates compared against each element of array.
  • comparator: optional (arrVal, othVal) => boolean; truthy means treat the pair as equal for removal.
  • Returns: the same array reference after removals.
1

Deep equality with _.isEqual

A fresh object literal in values can still match a row when the comparator performs a structural compare.

javascript
import pullAllWith from "lodash/pullAllWith";
import isEqual from "lodash/isEqual";

const rows = [
  { a: 1, b: { c: 2 } },
  { a: 9 }
];
pullAllWith(rows, [{ a: 1, b: { c: 2 } }], isEqual);
// rows is now [{ a: 9 }]
Try it Yourself
2

Numeric tolerance

Custom comparators can express ranges—for example removing every reading near a calibration anchor.

javascript
import pullAllWith from "lodash/pullAllWith";

const readings = [{ v: 10.1 }, { v: 10.0 }, { v: 20 }];
pullAllWith(readings, [{ v: 10 }], (a, b) => Math.abs(a.v - b.v) < 0.11);
// readings is now [{ v: 20 }]
Try it Yourself
3

Multi-field match

When only a subset of fields matters, compare them explicitly inside the comparator.

javascript
import pullAllWith from "lodash/pullAllWith";

const events = [
  { type: "click", target: "btn-a" },
  { type: "scroll", target: "main" },
  { type: "click", target: "btn-b" }
];
pullAllWith(events, [{ type: "click", target: "btn-a" }], (a, b) =>
  a.type === b.type && a.target === b.target
);
// events is now [{ type: "scroll", target: "main" }, { type: "click", target: "btn-b" }]
Try it Yourself

📋 _.pullAllWith vs _.pullAllBy vs _.differenceWith

APIMutationNote
_.pullAllWith(array, values, comparator)Mutates arrayPairwise comparator decides matches
_.pullAllBy(array, values, iteratee)Mutates arraySingle projection per side, SameValueZero on results
_.differenceWith(array, values, comparator)Returns a new arrayNon-destructive subtraction of exclusions

Pitfalls to avoid

Sym

Asymmetric comparators

Lodash may invoke (arrVal, othVal) in either order depending on internal pairing; keep comparisons logically symmetric when possible.

Perf

O(n×m) scans

Each element is checked against every ban entry; huge ban lists can get expensive compared to keyed lookups.

Copy

Undo buffers

Clone before pulling when you need snapshots for rollback or auditing.

❓ FAQ

Yes. Lodash removes matching elements in place and returns the same array reference, like pull, pullAll, and pullAllBy.
Return a truthy value when the two arguments should count as the same for removal (symmetric comparisons are easiest to reason about). Return falsy to keep the element.
pullAllBy maps each side through one iteratee and compares the projections with SameValueZero. pullAllWith hands both raw values to your comparator so you can express deep equality, tolerances, or multi-field rules.
Yes. That is a common choice for removing nested objects that are structurally equal but not the same reference.
Use import pullAllWith from "lodash/pullAllWith" or require("lodash/pullAllWith") for tree-shaking friendly bundles.

Summary

  • Purpose: _.pullAllWith(array, values, comparator) removes elements whose comparator reports a match against any value in values.
  • Mutation: the first array is updated in place; clone first when isolation matters.
  • Next: Lodash _.pullAt(), _.pullAllBy() (previous), or the array methods hub.
Did you know?

The comparator receives (arrVal, othVal)—the same pairing style as _.differenceWith() and _.intersectionWith(), except pullAllWith mutates the first array instead of allocating a new result.

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