Creates an array of values from array that are not included in the other given arrays, using SameValueZero for equality. Order follows the first array. Since Lodash 0.1.0. Unlike _.pullAll, 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 _.difference on an array. Start with this line.
Lodash
_.difference(array, [values])
Call
What it does
_.difference(array, [values])
Primary signature.
_.difference(array)
Call with an array argument.
Prefer import difference from "lodash/difference" when you want a smaller bundle.
Library declarations
Lodash
_.difference(array, [values])
Parameters
Parameter
Description
array
Required. Source to inspect
…values
Optional. Arrays whose elements are excluded
Return Value
Return Value
Description
*
The value returned by _.difference().
Lodash Examples
Example 1 — Official: Basic Difference
Keep values from the first array that are missing from the second.
Pick. Use difference when excludes already live in arrays.
Compatibility
Browser & Runtime Support
_.difference is a Lodash Array helper (since 0.1.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 0.1.0+
_.difference()
Available in [email protected] full builds and the lodash/difference 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
_.differenceLodash 0.1.0+
Bottom line: Safe for production once Lodash is loaded. Prefer import difference from "lodash/difference" for smaller builds. Not a native browser API — load Lodash first.
Frequently Asked Questions
_.difference(array, …values) returns a new array of values from the first array that are not included in any of the other given arrays. Equality uses SameValueZero. Order follows the first array.
No. Unlike _.pullAll, difference always returns a new array. The originals are unchanged.
_.without(array, …values) excludes individual values you list. _.difference excludes elements found inside other arrays. Pick based on whether your exclude list is already an array.
Objects are compared by reference (SameValueZero), not deep equality. Use _.differenceBy or _.differenceWith for custom comparison.
Yes. SameValueZero treats NaN as equal to NaN, so NaN in the first array is excluded if NaN appears in an exclusion array.
Use import difference from "lodash/difference" or require("lodash/difference") for tree-shaking. Full build: import _ from "lodash" then _.difference.