Lodash _.pullAllBy() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Array

Definition

Like _.pullAll, but accepts an iteratee to build the comparison key for each element of array and values. Returns the same array (mutated). Part of Lodash 4.x Array (since 4.0.0).

Warning: Unlike _.differenceBy, this method mutates array. For a custom comparator pair, use _.pullAllWith.

Syntax

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

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

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

Library declarations
Lodash
_.pullAllBy(array, values, [iteratee])

Parameters

ParameterDescription
arrayRequired. Array to mutate
valuesRequired. Array of values to match against
iterateeOptional. Projection; default _.identity

Return Value

Return ValueDescription
*Same array reference

Lodash Examples

Example 1 — Official: Property Shorthand

Remove objects whose x matches any ban object's x.

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

_.pullAllBy(array, [{ x: 1 }, { x: 3 }], "x");
// → [{ x: 2 }]
// array is also [{ x: 2 }]
Try It Yourself

How It Works

  1. Source. Four objects; two share x: 1.
  2. Iteratee. "x" reads the x property on each item.
  3. Ban keys. Values project to 1 and 3.
  4. Result. Only { x: 2 } remains — both x: 1 rows are gone.

Example 2 — Ban a Single Key

One entry in values still removes every matching projection.

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

_.pullAllBy(array, [{ x: 1 }], "x");
// → [{ x: 2 }, { x: 3 }]
Try It Yourself

How It Works

  1. Ban key. Only x: 1 is listed.
  2. Both gone. First and last objects project to 1.
  3. Kept. x: 2 and x: 3 stay in order.
  4. Tip. You do not need the whole object to match — only the projected key.

Example 3 — Function Iteratee

Pass a function when the key is not a plain property read.

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

_.pullAllBy(array, [{ n: 2 }], function (o) { return o.n; });
// → [{ n: 1 }, { n: 3 }]
Try It Yourself

How It Works

  1. Function. (o) => o.n is the comparison key.
  2. Ban. Values project to 2.
  3. Remove. The middle object with n: 2 leaves.
  4. Same as "n" shorthand for this simple case.

Example 4 — No Matching Keys

If no projected keys overlap, the array stays the same.

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

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

How It Works

  1. Ban key. Values project to 9.
  2. No overlap. Source keys are 1 and 2.
  3. Unchanged. Length and contents stay the same.
  4. Safe. Missing keys do not throw.

Example 5 — Why Not Plain pullAll?

Object identity fails — iteratee matching succeeds.

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

_.pullAll(a, [{ x: 1 }]);
// a still [{ x: 1 }, { x: 2 }]  — different object refs

_.pullAllBy(b, [{ x: 1 }], "x");
// b → [{ x: 2 }]
Try It Yourself

How It Works

  1. pullAll. Compares object references — the ban object is a new {x:1}.
  2. No remove. Nothing is the same reference, so a is unchanged.
  3. pullAllBy. Compares x values — key 1 matches.
  4. Rule. Prefer pullAllBy when matching objects by field.

Browser & Runtime Support

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

✓ Stable · Lodash 4.x

_.pullAllBy()

Available in [email protected] full builds and the lodash/pullAllBy modular import. There is no single native twin — closest patterns are a mutating filter loop or _.differenceBy 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
_.pullAllBy Lodash 4.x+

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

Frequently Asked Questions

_.pullAllBy(array, values, iteratee) removes elements from array when the iteratee result matches any iteratee result from values. It mutates array and returns the same reference.
Yes. Unlike _.differenceBy, pullAllBy changes the array you pass in. Clone first if you need the old contents.
It maps each element of array and each element of values to a comparison key. Removals use SameValueZero on those mapped results.
pullAll compares raw elements. pullAllBy compares iteratee output — so you can drop rows by id or property without matching whole objects.
Yes. A string like "x" is Lodash property shorthand — same idea as (item) => item.x for plain objects.
Use import pullAllBy from "lodash/pullAllBy" or require("lodash/pullAllBy") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.pullAllBy.

Next: _.pullAllWith()

Remove values when a custom comparator says they match.

_.pullAllWith() 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