Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)
How can I merge two arrays and remove the elements that are repeated in such a way that it makes an array with all unique values?

1 Answer

0 votes
by (13.1k points)
edited by

You can try it like this:
function makeUnique(arr){

var arr1=arr.concat();

for(var i=0; i<arr1.length; ++i)

 { 

for(var j=i+1; j<arr1.length; ++j)

 { 

if(arr1[i] === arr1[j]) 

arr1.splice(j--, 1); 

} } 

return arr1;

 }

var a=[“apple”,”banana”];

var b=[“banana”,”pineapple”];

makeUnique(a.concat(b));

Want to become a Web Developer, here's a Web Development Courses for you!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Sep 20, 2019 in C Programming by Himadri Roy (120 points)

Browse Categories

...