Similar to _.without, but returns the values from array that are not present in the other arrays (official Underscore docs). Stable Array helper — not deprecated.
Pass the required arguments shown below. Underscore array helpers usually return a new value — check whether the source array is mutated.
Syntax
Call _.difference. Start with this line.
Underscore
_.difference(array, *others)
Call
What it does
_.difference(array, *others)
Primary signature.
_.difference(...)
Call with the arguments your case needs.
Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.
Library declarations
Underscore
_.difference(array, *others)
Parameters
Parameter
Description
array
Required. Base list to take values from
*others
Optional. Zero or more arrays to subtract
Return Value
Return Value
Description
*
New array of non-matching values
Underscore.js Examples
Example 1 — Official: Subtract One Array
Keep values from the first array that are missing from the second.
Empty others. Nothing to exclude → copy of the base.
No overlap. No matches → full base returned.
Safe. Never throws on empty lists.
Compatibility
Browser & Runtime Support
_.difference ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.
✓ Stable · Underscore 1.x
_.difference()
Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.
100%With Underscore 1.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
_.differenceUnderscore 1.x+
Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).
Frequently Asked Questions
_.difference(array, *others) returns values from the first array that are not present in any of the other arrays. Official example: _.difference([1, 2, 3, 4, 5], [5, 2, 10]) → [1, 3, 4].
As many as you like. Pass the base array first, then any number of other arrays: _.difference(a, b, c).
No. Duplicates in the first array are kept. It only drops values that appear in the other arrays: _.difference([1, 1, 2], [2]) → [1, 1].
The order of the first array. Surviving values keep their original positions.
With strict equality (===). Primitives match by value; objects and arrays match by reference.
_.without takes loose values (arr, 1, 2). _.difference takes other arrays (arr, [1, 2]). Both use strict equality on the first array.