Like _.difference, except it accepts an iteratee invoked for each element of array and values to build the compare key. Order and references come from the first array. Since Lodash 4.0.0. Unlike _.pullAllBy, it returns a new array.
Pass the required arguments shown below. Lodash Array helpers usually return a new value — check whether the source array is mutated.
Syntax
Call _.differenceBy on an array. Start with this line.
Lodash
_.differenceBy(array, [values], [iteratee])
Call
What it does
_.differenceBy(array, [values], [iteratee])
Primary signature.
_.differenceBy(array)
Call with an array argument.
Prefer import differenceBy from "lodash/differenceBy" when you want a smaller bundle.
Library declarations
Lodash
_.differenceBy(array, [values], [iteratee])
Parameters
Parameter
Description
array
Required. Source to inspect
…values
Optional. Arrays whose projected values are excluded
difference. Objects are different references → nothing excluded.
differenceBy. Compare x → x: 1 matches and drops.
Lesson. Use By when “same shape” matters more than “same instance.”
Next. Need a custom equality test? Use _.differenceWith.
Compatibility
Browser & Runtime Support
_.differenceBy 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.0+
_.differenceBy()
Available in [email protected] full builds and the lodash/differenceBy modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 4.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.differenceByLodash 4.0+
Bottom line: Safe for production once Lodash is loaded. Prefer import differenceBy from "lodash/differenceBy" for smaller builds. Not a native browser API — load Lodash first.
Frequently Asked Questions
It is like _.difference, but each element is passed through an iteratee first. Lodash compares the projected values with SameValueZero, then returns matching originals from the first array that are not excluded.
No. Unlike _.pullAllBy, it always returns a new array. Inputs are unchanged.
Yes. The iteratee runs on elements of the first array and on every flattened element from the exclusion arrays before comparison.
A missing iteratee behaves like identity — same idea as _.difference for the same array arguments.
Use differenceWith when you need a custom comparator (for example deep equality or a tolerance). Use differenceBy when one projected key or transform is enough.
Use import differenceBy from "lodash/differenceBy" or require("lodash/differenceBy") for tree-shaking. Full build: import _ from "lodash" then _.differenceBy.