Lodash _.pullAllBy() method

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

What you’ll learn

  • How _.pullAllBy(array, values, iteratee) compares mapped keys instead of whole object references.
  • Why this extends _.pullAll() when rows carry ids, codes, or other stable fields.
  • How string shorthand paths differ from custom iteratee functions for the projection step.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Read _.pullAll() and _.pull() first; you should be comfortable with iteratees as in _.differenceBy()-style APIs.

  • 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

_.pullAllBy removes elements from the first array when their projected value matches the projection of any entry in the values array. It is the pull-family counterpart to other “By” helpers: same mutation story, but comparisons happen after your iteratee runs.

Project first

Compare ids, codes, or numeric features instead of whole object identity.

In place

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

Shorthand paths

Pass a string path such as groupId for simple property access on plain objects.

Syntax

javascript
_.pullAllBy(array, values, [iteratee=_.identity])
  • array: collection to mutate.
  • values: array of reference values; each is mapped with iteratee to build the exclusion set.
  • iteratee: string path, function, or built-in shorthand applied to elements of both array and values.
  • Returns: the same array reference after removals (SameValueZero on mapped results).
1

Property path shorthand

A string iteratee picks a field from every row; any row whose x matches a value entry’s x is removed.

javascript
import pullAllBy from "lodash/pullAllBy";

const points = [{ x: 1 }, { x: 2 }, { x: 3 }, { x: 1 }];
pullAllBy(points, [{ x: 1 }, { x: 3 }], "x");
// points is now [{ x: 2 }]
Try it Yourself
2

Rows keyed by id

The values array only needs enough shape for the iteratee—lightweight stubs with the same id field are enough to ban every matching row.

javascript
import pullAllBy from "lodash/pullAllBy";

const users = [
  { id: 1, name: "Ada" },
  { id: 2, name: "Bob" },
  { id: 1, role: "admin" }
];
pullAllBy(users, [{ id: 1 }], "id");
// users is now [{ id: 2, name: "Bob" }]
Try it Yourself
3

Function iteratee

Use a function when the comparison key is derived—for example bucketing floats with Math.floor.

javascript
import pullAllBy from "lodash/pullAllBy";

const samples = [2.5, 2.1, 3.7];
pullAllBy(samples, [2.2], Math.floor);
// samples is now [3.7]
Try it Yourself

📋 _.pullAllBy vs _.pullAll vs _.differenceBy

APIMutationNote
_.pullAllBy(array, values, iteratee)Mutates arrayRemoves in place when projections match the ban list
_.pullAll(array, values)Mutates arrayCompares raw elements only
_.differenceBy(array, values, iteratee)Returns a new arrayUse when you must keep the original untouched

Pitfalls to avoid

Key

Colliding projections

If the iteratee maps different rows to the same primitive, pulling one criterion can remove more rows than you visually associate with a single value object.

Path

Deep paths

String shorthand covers simple property names; deeply nested access usually belongs to a function iteratee or get-style helpers before pulling.

Cmp

Need richer equality

When projections are not enough, use _.pullAllWith() and supply an explicit comparator.

❓ FAQ

Yes. Matching elements are removed in place and Lodash returns the same array reference, just like pull and pullAll.
It maps each element of the target array and each element of the values array to a comparison key. Removals use SameValueZero on those mapped results.
pullAll compares raw elements. pullAllBy compares the iteratee output, so you can drop rows by id, tag, or any stable projection without matching whole objects.
Yes. Lodash treats shorthand strings like "id" as property accessors, equivalent to (item) => item.id for plain objects.
Use import pullAllBy from "lodash/pullAllBy" or require("lodash/pullAllBy") for tree-shaking friendly bundles.

Summary

  • Purpose: _.pullAllBy(array, values, iteratee) removes elements whose iteratee result matches any mapped value entry (SameValueZero).
  • Mutation: the first array is updated in place; clone before calling when isolation matters.
  • Next: Lodash _.pullAllWith(), _.pullAll() (earlier in this track), or the array methods hub.
Did you know?

When mapped primitives are not enough, use _.pullAllWith() so a comparator function can decide each (arrVal, othVal) pair.

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