jQuery.unique(array) (alias $.unique) sorts an array of DOM elements in place, removes duplicate node references, and returns that array in document order (added in jQuery 1.1.3). Since jQuery 3.0 it is only an alias of $.uniqueSort().
Remember
$.unique(domArray) → same array, sorted + deduped
// Duplicate = same node object (identity), not same HTML
// DOM elements only — not strings or numbers
// Modern name (same function in jQuery 3+):
$.uniqueSort(domArray)
Collect DOM nodes into a plain array, then unique (or uniqueSort) them.
Build a plain array of DOM elements (.get() / .toArray()).
Optionally merge arrays with $.merge or concat.
Call $.unique(arr) — or $.uniqueSort(arr) in new code.
Use the same array afterward (it is mutated in place).
Piece
Required?
Role
array
Yes
Plain JS array of DOM elements
Return
—
Same array, sorted + deduped (document order)
Mutation
—
In place — original array is changed
Pseudocode
Pseudocode
function unique(array):
// DOM elements only
sort array into document order
remove entries that are the same node object
return array // mutated in place
// Typical flow:
nodes = $("div").get()
$.merge(nodes, $(".dup").get())
$.unique(nodes) // or $.uniqueSort(nodes)
Reference
Cheat Sheet
Keep these facts handy while reading legacy jQuery code.
Three slots. The array holds three references to that same object.
Unique.$.unique keeps one copy and sorts the array.
In place.nodes itself shrinks — no new array is created.
Example 2 — Look-Alike Nodes Stay Separate
Different elements with the same class are not duplicates.
jQuery
var items = $("li.item").get(); // three different <li> nodes
console.log(items.length); // 3
$.unique(items);
console.log(items.length); // 3 (still three nodes)
Shuffled input. Nodes start as third, first, second.
Sort.$.unique reorders them as they appear in the document.
No dupes here. Length stays 3; only order changes.
Why. Document order makes later DOM walks predictable.
Example 4 — Migrate to $.uniqueSort()
In jQuery 3+, both names run the same function.
jQuery
var a = $("nav a").get();
$.merge(a, $(".footer-link").get());
$.unique(a);
var b = $("nav a").get();
$.merge(b, $(".footer-link").get());
$.uniqueSort(b);
console.log(a.length === b.length); // true
// Prefer $.uniqueSort in new code
Same merge. Both arrays start from the same selector overlap.
Legacy.$.unique(a) still works on jQuery 3.x.
Modern.$.uniqueSort(b) is the supported name.
Migrate. Rename $.unique → $.uniqueSort with no other change.
Edge Cases & Pitfalls
Check these before calling unique on real node lists.
deprecated
Prefer uniqueSort
Since jQuery 3.0, $.unique is only an alias. Use $.uniqueSort() in new code.
DOM only
Not for strings or numbers
Pass DOM elements only. For primitives, use Set or filter — not $.unique.
identity
Same markup ≠ duplicate
Two different nodes with identical HTML are kept. Only repeated references to one node are removed.
array
Needs a plain array
Do not pass a jQuery object. Convert with .get() or .toArray() first.
Compatibility
Browser Support
jQuery.unique() has been available since jQuery 1.1.3 and is deprecated since jQuery 3.0 as an alias of $.uniqueSort(). Prefer $.uniqueSort() in all modern browsers with jQuery loaded.
✓ Deprecated · jQuery 3.0
jQuery.unique()
Works in Chrome, Firefox, Safari, and Edge with jQuery 1.1.3+. Prefer $.uniqueSort() for new code. DOM-only — not for Node.js without a DOM.
LegacyPrefer uniqueSort
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
$.unique()Legacy alias
Bottom line: Learn $.unique() for legacy jQuery. Write $.uniqueSort(arr) in new projects.
Analysis
Performance Notes
Approach
Cost
Best for
$.uniqueSort(arr) / $.unique(arr)
Sort + scan
Small/medium DOM node arrays
Let jQuery merge selectors
Often enough
Normal app code (rarely call unique yourself)
Huge node lists
Noticeable
Avoid re-running in hot loops
You rarely need this in application code — jQuery uses it internally. When you do, run it once after merging node arrays, not on every click.
Remember
Key Takeaways
Role: dedupe + sort DOM node arrays in place.
Modern: use $.uniqueSort() instead of $.unique().
Identity: same node object only — not similar HTML.
Status: deprecated in jQuery 3.0.
One line: treat $.unique as the old name for $.uniqueSort — DOM identity dedupe in document order, not a general array unique.
Frequently Asked Questions
jQuery.unique(array) sorts an array of DOM elements in place, removes duplicate node references, and returns that array in document order. It only works on DOM elements — not strings, numbers, or plain objects.
Yes. Since jQuery 3.0, $.unique() is deprecated and kept as an alias of $.uniqueSort(). Both names call the same function. Prefer $.uniqueSort() in new code.
Two entries are duplicates only when they are the exact same DOM node object. Two different elements with identical class or text are not duplicates — jQuery compares node identity, not attributes.
No. Pass a native array of DOM nodes. Convert with .get() or .toArray() first: var nodes = $("div").get(); $.unique(nodes);
No. For primitives, use a Set or Array.filter() instead. $.unique is a DOM-only helper, mainly used inside jQuery.
Prefer $.uniqueSort() for new code. Treat $.unique() as the legacy name you may still see in older tutorials — migrating is a rename with no behavior change in jQuery 3+.