Produces a duplicate-free version of the array, using === to test equality. Only the first occurrence of each value is kept (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 _.uniq. Start with this line.
Underscore
_.uniq(array, [isSorted], [iteratee])
Call
What it does
_.uniq(array, [isSorted], [iteratee])
Primary signature.
_.uniq(...)
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
_.uniq(array, [isSorted], [iteratee])
Parameters
Parameter
Description
array
Required. Source to de-duplicate
isSorted
Optional. true enables the faster adjacent-compare path
iteratee
Optional. Function (or shorthand) that computes the uniqueness key
Return Value
Return Value
Description
*
New array of unique values (first-seen)
Underscore.js Examples
Example 1 — Official Docs De-dupe
The classic Underscore example — keep the first of each value.
Key by id. The iteratee returns u.id for each user.
First wins. The first user with id: 1 is kept; the duplicate is skipped.
Objects by default. Without an iteratee, look-alike objects would both stay (different references).
Use case. Clean API merges or lists where identity is a property, not the object itself.
Compatibility
Browser & Runtime Support
_.uniq (alias _.unique) 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
_.uniq()
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
_.uniqUnderscore 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
_.uniq(array) returns a new array with duplicates removed, keeping only the first occurrence of each value in its original order.
Yes. _.unique is an alias for _.uniq — both behave the same.
With strict equality (===). Primitives match by value; objects match by reference.
If the array is already sorted, pass true as the second argument. Underscore then uses a faster path that only compares each value to the previous one.
An iteratee lets you decide uniqueness from a transformed key — for example Math.floor, or a property like user.id. The original item (not the key) is kept.
_.uniq de-duplicates one array. _.union merges several arrays, then de-duplicates. _.union(arr) behaves like _.uniq(arr).