Like _.union, except it accepts a comparator to decide when two elements are duplicates. Called as (arrVal, othVal). Order and references come from the first occurrence. Since Lodash 4.0.0.
Pass the required arguments shown below. Lodash Array helpers usually return a new value — check whether the source array is mutated.
Syntax
Call _.unionWith on an array. Start with this line.
Lodash
_.unionWith([arrays], [comparator])
Call
What it does
_.unionWith([arrays], [comparator])
Primary signature.
_.unionWith(array)
Call with an array argument.
Prefer import unionWith from "lodash/unionWith" when you want a smaller bundle.
Keep first.name: "Ada" from the earlier array wins.
Skip later."Updated" never enters the result.
Tip. Put preferred sources first when merging.
Compatibility
Browser & Runtime Support
_.unionWith 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+
_.unionWith()
Available in [email protected] full builds and the lodash/unionWith 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
_.unionWithLodash 4.0+
Bottom line: Safe for production once Lodash is loaded. Prefer import unionWith from "lodash/unionWith" for smaller builds. Not a native browser API — load Lodash first.
Frequently Asked Questions
It merges multiple arrays into one unique list, using a custom comparator (arrVal, othVal) to decide when two elements are duplicates. Order and references follow the first occurrence across the combined arrays.
No. It returns a new array. Source arrays are unchanged.
Return a truthy value when the two arguments should count as the same element (a duplicate). Return falsy when they are distinct.
The earliest element in combined argument order wins. Later matches are skipped.
Use unionBy when one projected key or transform is enough (for example "id"). Use unionWith for deep equality, tolerances, or multi-field rules.
Use import unionWith from "lodash/unionWith" or require("lodash/unionWith") for tree-shaking. Full build: import _ from "lodash" then _.unionWith.