Sorts an array of DOM elements, in place, with the duplicates removed. Note that this only works on arrays of DOM elements, not strings or numbers.

jQuery.unique(array)🡢 Array

array ArrayThe Array of DOM elements.

As of jQuery 3.0, this method is deprecated and just an alias of jQuery.uniqueSort(). Please use that method instead.

The $.unique() function searches through an array of objects, sorting the array, and removing any duplicate nodes. A node is considered a duplicate if it is the exact same node as one already in the array; two different nodes with identical attributes are not considered to be duplicates. This function only works on plain JavaScript arrays of DOM elements, and is chiefly used internally by jQuery. You probably will never need to use it.

As of jQuery 1.4 the results will always be returned in document order.

Removes any duplicate elements from the array of divs.

<div>There are 6 divs in this document.</div>
<div class="dup"></div>
<div class="dup"></div>
<div class="dup"></div>
div {
  color: blue;
// unique() must take a native array
var divs = $("div").get();

// Add 3 elements of class dup too (they are divs)
divs = divs.concat($(".dup").get());
  .text("Pre-unique there are " + divs.length + " elements.");

divs = jQuery.unique(divs);
  .text("Post-unique there are " + divs.length + " elements.")
  .css("color", "red");

Looking for a Web Developer?


Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)