SOURCE

const arrA = [1,2,3];    //数组A
const arrB = [2,3,4];    //数组B
let result = undefined;  //结果

//ES6方式
let setA = new Set(arrA);
let setB = new Set(arrB);

//一、交集(A有,B也有)
result = arrA.filter(o=>setB.has(o));
console.log('ES6交集:'+result);

//二、差集(A有,B没有)
result = arrA.filter(o=>!setB.has(o));
console.log('ES6差集:'+result);

//三、并集(A有或B有)
result = Array.from(new Set([...arrA, ...arrB]));
console.log('ES6并集:'+result);


//lodash方式
//一、交集(A有,B也有)
result = _.intersection(arrA,arrB);
console.log('lodash交集:'+result);

//二、差集(A有,B没有)
result = _.difference(arrA,arrB);
console.log('lodash差集:'+result);

//三、并集(A有或B有)
result = _.union(arrA,arrB);
console.log('lodash并集:'+result);
console 命令行工具 X clear

                    
>
console