Like _.difference, except it accepts a comparator invoked to compare elements of array to values. Called as (arrVal, othVal). Order and references come from the first array. Since Lodash 4.0.0. Unlike _.pullAllWith, 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 _.differenceWith on an array. Start with this line.
Lodash
_.differenceWith(array, [values], [comparator])
Call
What it does
_.differenceWith(array, [values], [comparator])
Primary signature.
_.differenceWith(array)
Call with an array argument.
Prefer import differenceWith from "lodash/differenceWith" when you want a smaller bundle.
vs pullAllWith. That API mutates; this one does not.
Safe. Prefer With when you must keep the original array.
Compatibility
Browser & Runtime Support
_.differenceWith 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+
_.differenceWith()
Available in [email protected] full builds and the lodash/differenceWith 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
_.differenceWithLodash 4.0+
Bottom line: Safe for production once Lodash is loaded. Prefer import differenceWith from "lodash/differenceWith" for smaller builds. Not a native browser API — load Lodash first.
Frequently Asked Questions
It is like _.difference, but you supply a comparator (arrVal, othVal) that returns true when two values should count as a match for exclusion. Survivors come from the first array in original order.
No. Unlike _.pullAllWith, it always returns a new array. Inputs are unchanged.
Return true when the two arguments should be treated as the same for removal. Return false when they are distinct. Symmetry is expected for predictable results.
Use differenceBy when one projected key or transform is enough (for example "id" or Math.floor). Use differenceWith for deep equality, tolerances, or multi-field rules.
Yes. _.differenceWith(objects, others, _.isEqual) is the common deep-equality pattern from the official docs.
Use import differenceWith from "lodash/differenceWith" or require("lodash/differenceWith") for tree-shaking. Full build: import _ from "lodash" then _.differenceWith.