jQuery.unique()
**DEPRECATED in Version 3.0**
JQ Home <<
Utilities <<
jQuery.unique()
Array object creation.
Description
The jQuery.unique()
jQuery General utility method, returns an array of sorted DOM elements with duplicates removed.
Shorthand version $.unique()
- The
jQuery.unique()
jQuery General utility method only works on arrays of DOM elements, not strings or numbers. - The returned array will always be in document order.
This method was deprecated in jQuery 3.0 and and is now used as an alias for jQuery.uniqueSort() which should be used instead.
Syntax
Signature | Description |
---|---|
jQuery.unique( array ) | Return an array of sorted DOM elements with duplicates removed. |
Parameters
Parameter | Description | Type |
---|---|---|
array | The array of DOM elements. | Array |
Return
An Array
object.
jQuery.unique( array )
Example
Utilities << Top
Return an array of sorted DOM elements with duplicates removed.
In the example below when we press the button we create an array variable of the table DOM elements on the page. There are three tables on the page comprised of the 'Syntax' and 'Parameter' tables above, both of which have a
class of 'jskeywordtable' and the 'Other Tutorial Sites' table within the footer of the page. We then concatenate onto this array and output a message displaying the array length. After this we use the
jQuery.uniqueSort()
jQuery General utility method on the array, which removes the duplicates we added to the array. Finally we output a message displaying the array length again.
$(function(){
$('#btn7').one('click', function(){
var domElem = $('table').get();
domElem = domElem.concat($('.jskeywordtable').get());
$('#div7').append('<code>domElem</code> contains: ' + domElem.length + ' tables.<br>');
domElem = jQuery.unique(domElem);
$('#div7').append('<code>domElem</code> contains: ' + domElem.length + ' tables.<br>');
});
});
div7. Some initial text.
Related Tutorials
jQuery Intermediate Tutorials - Lesson 9 - jQuery General Utilities