Try following:
function inArray(needle, haystack) {
var length = haystack.length;
for(var i = 0; i < length; i++) {
if(haystack[i] == needle) return true;
}
return false;
}
var arr = [];
a.forEach( function(item) {
if (!in_array(item, arr)) {
arr.push(item);
}
});
in_array reference: JavaScript equivalent of PHP's in_array()
It looks if an item is existing and if it's distinct (doesn't exist) it push the item into the array.
Or the jQuery solution mentioned inside the comments: Remove Duplicates from JavaScript Array
Which is following:
var names = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"];
var uniqueNames = [];
$.each(names, function(i, el){
if($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
});
I posted the codes to ensure that someone finding this inside google finds some actual code and not just links that maybe are already down or closed.