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).
Remember
$.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)
Collect DOM nodes into a plain array, merge if needed, then uniqueSort.
Build an array of DOM elements (.get() / .toArray()).
Optionally merge more nodes with $.merge or concat.
Call $.uniqueSort(arr) to dedupe and sort in place.
Use the same array afterward (it is mutated).
Piece
Required?
Role
array
Yes
Array or array-like of DOM elements
Return
—
Same list, sorted + deduped (document order)
Mutation
—
In place — the input list is changed
Pseudocode
Pseudocode
function uniqueSort(array):
// DOM elements only
sort array into document order
remove entries that are the same node object
return array // mutated in place
// Typical / official flow:
divs = $("div").get()
divs = divs.concat($(".dup").get())
divs = $.uniqueSort(divs)
Reference
Cheat Sheet
Keep these facts handy while deduping DOM node lists.
Three slots. The array holds three references to that object.
uniqueSort. Keeps one copy and sorts the array.
In place.nodes itself shrinks — no new array is created.
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)
Shuffled input. Nodes start as third, first, second.
Sort.$.uniqueSort 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.
Edge Cases & Pitfalls
Check these before calling uniqueSort on real node lists.
DOM only
Not for strings or numbers
Pass DOM elements only. For primitives, use Set or filter — not $.uniqueSort.
identity
Same markup ≠ duplicate
Two different nodes with identical HTML are kept. Only repeated references to one node are removed.
array
Needs a native array / array-like
Do not pass a jQuery object. Convert with .get() or .toArray() first.
legacy
$.unique is the old name
In jQuery 3+, $.unique() is a deprecated alias of this method. Prefer $.uniqueSort().
Compatibility
Browser Support
jQuery.uniqueSort() is available as uniqueSort since jQuery 1.12 / 2.2 (earlier releases used $.unique()). It needs a browser DOM — not Node.js without a DOM polyfill.
✓ jQuery 1.12+ / 2.2+ · Browsers
jQuery.uniqueSort()
Works in Chrome, Firefox, Safari, and Edge with a supported jQuery version. Prefer $.uniqueSort() over deprecated $.unique(). DOM-only.
100%Browser support
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
$.uniqueSort()Browsers
Bottom line: Use $.uniqueSort(arr) in the browser with jQuery. For Node.js, use a DOM environment or a different approach.
Analysis
Performance Notes
Approach
Cost
Best for
$.uniqueSort(arr)
Sort + scan
Small/medium DOM node arrays
Let jQuery merge selectors
Often enough
Normal app code (rarely call uniqueSort 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.
Identity: same node object only — not similar HTML.
Order: results are always in document order.
Name: prefer uniqueSort over deprecated $.unique.
One line: use $.uniqueSort for DOM identity dedupe in document order after merging node arrays — not as a general array unique.
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.
No. Pass a native array (or array-like) of DOM nodes. Convert with .get() or .toArray() first: var nodes = $("div").get(); $.uniqueSort(nodes);
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.