Lodash _.pullAllWith() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Array

Definition

Like _.pullAll, but accepts a comparator invoked as (arrVal, othVal) to decide matches. Returns the same array (mutated). Part of Lodash 4.x Array (since 4.6.0).

Warning: Unlike _.differenceWith, this method mutates array. For a single projected key, prefer _.pullAllBy.

Syntax

Call _.pullAllWith on an array. Start with this line.

Lodash
_.pullAllWith(array, values, [comparator])
CallWhat it does
_.pullAllWith(array, values, [comparator])Primary signature.
_.pullAllWith(array)Call with an array argument.

Prefer import pullAllWith from "lodash/pullAllWith" when you want a smaller bundle.

Library declarations
Lodash
_.pullAllWith(array, values, [comparator])

Parameters

ParameterDescription
arrayRequired. Array to mutate
valuesRequired. Array of values to match against
comparatorOptional. (arrVal, othVal) => boolean

Return Value

Return ValueDescription
*Same array reference

Lodash Examples

Example 1 — Official: Deep Equal with _.isEqual

Remove the object that is structurally equal to the ban entry.

Lodash
var array = [
  { x: 1, y: 2 },
  { x: 3, y: 4 },
  { x: 5, y: 6 }
];

_.pullAllWith(array, [{ x: 3, y: 4 }], _.isEqual);
// → [{ x: 1, y: 2 }, { x: 5, y: 6 }]
Try It Yourself

How It Works

  1. Source. Three objects with x and y.
  2. Ban. A new object { x: 3, y: 4 } — different reference.
  3. isEqual. Deep compare finds the middle item equal.
  4. Mutates. Middle object is removed; ends stay.

Example 2 — Custom Field Comparator

Match on one field without deep-comparing the whole object.

Lodash
var array = [{ n: 1 }, { n: 2 }, { n: 3 }];

_.pullAllWith(array, [{ n: 2 }], function (a, b) {
  return a.n === b.n;
});
// → [{ n: 1 }, { n: 3 }]
Try It Yourself

How It Works

  1. Comparator. Returns true when n values are equal.
  2. Ban. Looks for n: 2.
  3. Remove. Middle object matches and leaves.
  4. Note. For this case _.pullAllBy(array, [{n:2}], "n") is shorter.

Example 3 — No Matching Values

If the comparator never returns truthy, the array stays the same.

Lodash
var array = [{ x: 1 }, { x: 2 }];

_.pullAllWith(array, [{ x: 9 }], _.isEqual);
// → [{ x: 1 }, { x: 2 }]
Try It Yourself

How It Works

  1. Ban. { x: 9 } is not deep-equal to either item.
  2. No removals. Length and contents stay the same.
  3. Still the API. You get the same array reference back.
  4. Safe. Missing matches do not throw.

Example 4 — Multiple Ban Objects

Every array item that matches any ban entry is removed.

Lodash
var array = [
  { x: 1, y: 2 },
  { x: 3, y: 4 },
  { x: 5, y: 6 }
];

_.pullAllWith(
  array,
  [{ x: 1, y: 2 }, { x: 5, y: 6 }],
  _.isEqual
);
// → [{ x: 3, y: 4 }]
Try It Yourself

How It Works

  1. Two bans. First and third objects each match one ban entry.
  2. Both leave. Only the middle object remains.
  3. Order. Relative order of survivors is preserved.
  4. Same idea as pulling multiple values with pullAll, but deep.

Example 5 — Why Not Plain pullAll?

Reference equality fails — a comparator succeeds.

Lodash
var a = [{ x: 1, y: 2 }, { x: 3, y: 4 }];
var b = [{ x: 1, y: 2 }, { x: 3, y: 4 }];

_.pullAll(a, [{ x: 3, y: 4 }]);
// a unchanged — different object refs

_.pullAllWith(b, [{ x: 3, y: 4 }], _.isEqual);
// b → [{ x: 1, y: 2 }]
Try It Yourself

How It Works

  1. pullAll. Compares references — the ban object is new.
  2. No remove. Nothing is the same reference, so a stays.
  3. pullAllWith. _.isEqual sees structural equality.
  4. Rule. Prefer pullAllWith (or pullAllBy) for object rows.

Browser & Runtime Support

_.pullAllWith is a Lodash 4.x Array helper (since 4.6.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.x

_.pullAllWith()

Available in [email protected] full builds and the lodash/pullAllWith modular import. There is no single native twin — closest patterns are a mutating filter with a custom equals, or _.differenceWith for a new array.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.pullAllWith Lodash 4.x+

Bottom line: Safe for production once Lodash is loaded. Prefer import pullAllWith from "lodash/pullAllWith" for smaller bundles. Remember: this helper mutates — pair with differenceWith when you need immutability.

Frequently Asked Questions

_.pullAllWith(array, values, comparator) removes elements from array when comparator(arrVal, othVal) is truthy for any value in the values list. It mutates array and returns the same reference.
Yes. Unlike _.differenceWith, pullAllWith changes the array you pass in. Clone first if you need the old contents.
Return a truthy value when the two arguments should count as a match for removal. Return falsy to keep the element. Symmetric rules are easiest to reason about.
pullAllBy maps each side through one iteratee and compares projections with SameValueZero. pullAllWith hands both raw values to your comparator for deep equality, tolerances, or multi-field rules.
Yes. That is the usual 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. Full build: import _ from "lodash" then _.pullAllWith.

Next: _.pullAt()

Remove elements by index and get the removed values back.

_.pullAt() tutorial →

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.

10 people found this page helpful