jQuery.uniqueSort(array) (alias $.uniqueSort) sorts an array or array-like list of DOM elements in place, removes duplicate node references, and returns that list in document order (added as uniqueSort in jQuery 1.12 / 2.2).
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$.uniqueSort(domArray) → same array, sorted + deduped
// Duplicate = same node object (identity), not same HTML
// DOM elements only — not strings or numbers
// Official pattern:
divs = $("div").get().concat($(".dup").get())
divs = $.uniqueSort(divs)
Call
What it does
uniqueSort()
Learn jQuery.uniqueSort(): remove duplicate DOM node references, sort into document order, official merge demo, vs deprecated $.unique, 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 an array of DOM elements (.get() / .toArray()).
Step 2
Optionally merge more nodes with $.merge or concat.
Step 3
Call $.uniqueSort(arr) to dedupe and sort in place.
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 — Official Merge Pattern
Official jQuery API idea: concat overlapping selections, then uniqueSort.
jQuery
var divs = $("div").get();
divs = divs.concat($(".dup").get());
console.log(divs.length); // e.g. 8 (6 + 2 overlaps)
divs = $.uniqueSort(divs);
console.log(divs.length); // e.g. 6
Three slots. The array holds three references to that object.
uniqueSort. Keeps one copy and sorts the array.
Example 3 — 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
$.uniqueSort(items);
console.log(items.length); // 3 (still three nodes)
Three elements. Each <li class="item"> is its own DOM object.
Same class ≠ same node. Attributes and text are ignored for dedupe.
uniqueSort. Nothing is removed because no reference repeats.
Frequently Asked Questions
jQuery.uniqueSort(array) sorts an array or array-like list of DOM elements in place, removes duplicate node references, and returns that list in document order. It only works on DOM elements — not strings, numbers, or plain objects.
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.
They perform the same job. $.unique() was the original name. It was renamed to $.uniqueSort() (available as uniqueSort since 1.12/2.2) and $.unique became a deprecated alias in jQuery 3.0. Prefer $.uniqueSort() in new code.
jQuery.uniqueSort(array) is the utility — pass a native array (or array-like) of DOM nodes, e.g. var nodes = $("div").get(); $.uniqueSort(nodes);. Since jQuery 3.7, collections also have a separate .uniqueSort() instance method you call directly on the collection: $("div").uniqueSort(). See the .uniqueSort() traversing tutorial for that API.
No. For primitives, use a Set or Array.filter() instead. $.uniqueSort is a DOM-only helper, mainly used inside jQuery.
Rarely in app code — jQuery uses it internally. Reach for it when you merge node arrays from multiple selectors and need one de-duplicated list in document order.