we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "prevent adding the item twice in an array javascript"
Deanna
03 Jan 2019
1var names = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"];
2var uniqueNames = [];
3$.each(names, function(i, el){
4if($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
5});