Creates an array of unique values that is the symmetric difference of the given arrays. Shared values cancel; values unique to an odd number of arrays stay. Result order follows first appearance. Part of Lodash 4.x Array.
Pass the required arguments shown below. Lodash Array helpers usually return a new value — check whether the source array is mutated.
Syntax
Call _.xor on an array. Start with this line.
Lodash
_.xor([arrays])
Call
What it does
_.xor([arrays])
Primary signature.
_.xor(array)
Call with an array argument.
Prefer import xor from "lodash/xor" when you want a smaller bundle.
Library declarations
Lodash
_.xor([arrays])
Parameters
Parameter
Description
arrays
Optional. One or more arrays to inspect
Return Value
Return Value
Description
*
New array of exclusive values
Lodash Examples
Example 1 — Official: Two-Array XOR
Overlap cancels; exclusive values from each side remain.
Empty peer. Nothing to cancel against → all of [1,2,3] survive.
Still new. The result is a new array, not a shared reference.
Safe. Neither case throws.
Compatibility
Browser & Runtime Support
_.xor is a Lodash 4.x Array helper. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 4.x
_.xor()
Available in [email protected] full builds and the lodash/xor 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
_.xorLodash 4.x+
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import xor from "lodash/xor" for smaller builds. Not a native browser API — load Lodash first.
Frequently Asked Questions
_.xor(...arrays) returns a new array of unique values that appear in an odd number of the given arrays — the symmetric difference. Shared values cancel out.
No. It returns a new array. All argument arrays stay unchanged.
difference subtracts later arrays from the first array only (directed). xor treats every array as a peer — values exclusive to any single side survive.
Lodash folds them left to right: xor(xor(a, b), c). A value survives if it ends up in an odd number of arrays after that fold.
SameValueZero — NaN matches NaN, +0 equals −0, primitives compare by value, objects by reference. Use _.xorBy or _.xorWith for custom keys or comparators.
Use import xor from "lodash/xor" or require("lodash/xor") for tree-shaking. Full build: import _ from "lodash" then _.xor.