Javatpoint Logo
Javatpoint Logo

jQuery.unique() method

The $.unique() method sorts an array of DOM elements and removes the duplicates. It returns the sorted array after removing the duplicates. This method is deprecated from jQuery version 3.0, and we can use jQuery.uniqueSort() method instead, that works similar to jQuery.unique() method.

This method searches through the array of objects, sorts the array, and removes the duplicate nodes. The node which is exactly the same as the node already existing in the array is considered to be the duplicate node. If nodes are different, but their attributes are the same will not be considered duplicates.

Syntax

This method accepts a single parameter which is defined as follows -

array: It is the array of DOM elements.

Let's see an illustration to understand the working of the $.unique() method.

Example

It is a simple example of using the $.unique() method. In this example, initially, there are two paragraph elements related to the para class. But we are using the .concat() method to create the duplicates of the paragraphs with class = "para". So, the $.unique() method will remove the duplicates created using the .concat() method.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery.unique() method





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA