let arr1 = [1,2,3,4,5];
let arr2 = [4,5,6,7,8];
//数组求交集
function arrayIntersection(arr1,arr2) {
//先去重
let arr1Unique = [...new Set(arr1)];
//去重转为set
let arr2UniqueSet = new Set(arr2);
return arr1Unique.filter(item=>arr2UniqueSet.has(item));
}
console.log(arrayIntersection(arr1,arr2));
标签:arrayIntersection,数组,交集,JavaScript,let,arr2,arr1
From: https://www.cnblogs.com/cqpanda/p/17083279.html