Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

prevent adding the item twice in an array javascript

var names = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"];
var uniqueNames = [];
$.each(names, function(i, el){
if($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #prevent #adding #item #array #javascript
ADD COMMENT
Topic
Name
9+4 =