The jQuery $.unique() function is used to removes duplicate elements only from an array of DOM elements. In the following article we have created a custom function called unique which removes duplicates from an array.
Example
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>jQuery Example</title>
<script type="text/javascript"
src="jquery.js">
</script>
<script type="text/javascript">
$(function () {
var arr = [10, 28, 33, 28, 64, 48, 33, 79, 48, 95];
$("#orig").html("Original array :" + arr.join(","));
arr = $.unique(arr);
$("#uniq").html("Unique array :" + arr.sort().join(","));
});
</script>
</head>
<script type="text/javascript">
$(function () {
var arr = [10, 28, 33, 28, 64, 48, 33, 79, 48, 95];
$("#orig").html("Given array are as follows :" + arr.join(","));
arr = arr.unique();
$("#uniq").html("Now the unique array are :" + arr.sort().join(","))
});
// Original function by Alien51
Array.prototype.unique = function () {
var arrVal = this;
var uniqueArr = [];
for (var i = arrVal.length; i--; ) {
var val = arrVal[i];
if ($.inArray(val, uniqueArr) === -1) {
uniqueArr.unshift(val);
}
}
return uniqueArr;
}
</script>
</head>
<body style="font-family: Verdana; font-size: small">
<div>
<p id="orig"></p>
<p id="uniq"></p>
</div>
</body>
</html>
Output

Note: The search is case-sensitive in case of a string array as the function does not consider "Out" and "out" as duplicate.