Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

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? 

1 Answer

0 votes
by (19.7k points)

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);

});

If you want to learn more about Javathen go through this Java tutorial by Intellipaat for more insights.  

Related questions

0 votes
1 answer
asked Feb 15, 2021 in Java by Jake (7k points)
0 votes
1 answer
0 votes
0 answers
asked Feb 18, 2021 in Java by Harsh (1.5k points)
0 votes
1 answer
0 votes
1 answer
asked Feb 20, 2021 in Java by Jake (7k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...