Skip to content Skip to sidebar Skip to footer

Remove Duplicates From Two Arrays Javascript

I have two arrays in javascript ,And I wand to remove duplicates from them var array1 = [1,2,3,4,5,6,7,8,9]; var array2 = [3,5,7,11,17,19]; I want the output to be [1,2,3,4,5,6,7

Solution 1:

var array1 = [1,2,3,4,5,6,7,8,9], array2 = [3,5,7,11,17,19];
var output = array1.concat(array2);
var output = output.filter(function (item, pos) {return output.indexOf(item) == pos});

DEMO


Post a Comment for "Remove Duplicates From Two Arrays Javascript"