Back
Below is my Javascript array:
var names = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"];
I want to remove the duplicates and put the unique values in a new array.
Can anyone tell me how to do it?
It gets simple with JQuery. You can use the below code implementation:
var names = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"];var uniqueNames = [];$.each(names, function(i, el){ if($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);});
var uniqueNames = [];
$.each(names, function(i, el){
if($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
});
If you want to learn more about Java, then go through this Java tutorial by Intellipaat for more insights.
31k questions
32.8k answers
501 comments
693 users