jQuery.uniqueSort( array )Returns: Array

Description: 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.

The $.uniqueSort() 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.

Prior to jQuery 3.0, this method was called jQuery.unique().

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


Removes any duplicate elements from the array of divs.

<!doctype html>
<html lang="en">
  <meta charset="utf-8">
  <title>jQuery.uniqueSort demo</title>
  div {
    color: blue;
  <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<div>There are 6 divs in this document.</div>
<div class="dup"></div>
<div class="dup"></div>
<div class="dup"></div>
// 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() );
$( "div" ).eq( 1 ).text( "Pre-unique there are " + divs.length + " elements." );
divs = jQuery.uniqueSort( divs );
$( "div" ).eq( 2 ).text( "Post-unique there are " + divs.length + " elements." )
  .css( "color", "red" );


© The jQuery Foundation and other contributors
Licensed under the MIT License.