Get all unique values in a JavaScript array (remove duplicates)

var names = ["a","b","c","d","e","e","f"];
var uniqueNames = [];
$.each(names, function(i, el){
    if($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
});
console.log(uniqueNames);

Output

["a", "b", "c", "d", "e", "f"]

Leave a Reply

Your email address will not be published. Required fields are marked *