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().
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$.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)
Call
What it does
unique()
Learn jQuery.unique(): the deprecated DOM dedupe helper (alias of uniqueSort), remove duplicate node references, sort into document order, migrate to $.uniqueSort, examples, pitfalls, and FAQs.
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Build a plain array of DOM elements (.get() / .toArray()).
Step 2
Optionally merge arrays with $.merge or concat.
Step 3
Call $.unique(arr) — or $.uniqueSort(arr) in new code.
Return Value
Return Value
Description
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
jQuery Examples
Example 1 — Duplicate Node References
The same DOM node listed three times collapses to one.
jQuery
var target = document.getElementById("panel");
var nodes = [target, target, target];
console.log(nodes.length); // 3
$.unique(nodes);
console.log(nodes.length); // 1
Three slots. The array holds three references to that same object.
Unique.$.unique keeps one copy and sorts the array.
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.
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+.