YouTip LogoYouTip

Misc Unique

# jQuery.unique() Method [![Image 3: jQuery Miscellaneous Methods](#)jQuery Miscellaneous Methods](#) ## Example Remove duplicate div elements from the array
There are 6 div blocks in the document
$(function(){// unique() gets an original array var divs = $("div").get(); // Add 3 div block elements divs = divs.concat( $(".dup").get()); $("div:eq(1)").text("After resorting there are " + divs.length + " elements."); divs = jQuery.unique(divs); $("div:eq(2)").text("After resorting there are " + divs.length + " elements.") .css("color", "red"); }) [Try it Β»](#) * * * ## Definition and Usage The $.unique() function is used to sort an array of DOM elements and remove duplicate elements. **Note:** 1. Only applicable to DOM element arrays, cannot process string or number arrays. 2. The "duplicate" here refers to two elements that are actually the same element (determined by strict equality "==="), for example, elements with the same attributes but different nodes are not considered duplicate elements. 3. In jQuery 3.0, this method has been deprecated, it's just an alias for jQuery.uniqueSort(). Please use that method instead. ## Syntax _$_.unique( array ) | Parameter | Description | | :--- | :--- | | _array_ | Array type The specified DOM element array. | * * jQuery Miscellaneous Methods](#) [](#)(#) (#)[](#)
← Misc HasdataMisc Trim β†’