从两个数组javascript中删除重复项

时间:2014-08-29 15:10:49

标签: javascript

我在javascript中有两个数组,我想从中删除重复项

var array1 = [1,2,3,4,5,6,7,8,9];
var array2 = [3,5,7,11,17,19];

我希望输出为[1,2,3,4,5,6,7,8,9,11,17,19]

1 个答案:

答案 0 :(得分: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