jQuery.uniqueSort()Method

jQuery 杂项方法jQuery Miscellaneous Methods

Examples

Remove duplicate div elements from an array

<div>There are 6 div blocks in the document</div> <div></div> <div class="dup"></div> <div class="dup"></div> <div class="dup"></div> <div></div> <script>
$(function () { //unique() must get an array var divs = $( "div" ).get(); //Add 3 div block elements divs = divs.concat( $( ".dup" ).get() ); $( "div:eq(1)" ).text( "After reordering, there are" + divs.length + "elements" ); divs = jQuery.uniqueSort( divs );$.uniqueSort(document.getElementsByTagName("div")); $( "div:eq(2)" ).text( "After reordering, there are" + divs.length + "elements" ) .css( "color", "red" ); })
</script>

Try it Yourself »

Definition and Usage

$The .uniqueSort() function searches the array object, sorts the array, and removes any duplicate nodes.

Note:Two different nodes with the same attributes are not considered duplicates. This function only applies to arrays of plain JavaScript DOM elements, mainly for internal jQuery use.
Before jQuery 3.0, this method was called jQuery.unique().



Syntax

$.uniqueSort(array)

Parameters Description
array Array type: the specified array of DOM elements.


jQuery 杂项方法jQuery Miscellaneous Methods

Other Extensions