如何在 JavaScript 中获取两个数组之间的差异?
有以下两个数组
var arr1 = ['a', 'b', 'c'];
var arr2 = ['b', 'c', 'd'];
let difference = arr1.filter(x => !arr2.includes(x)); //['a']
let intersection = arr1.filter(x => arr2.includes(x)); // ['b', 'c']
let difference2 = arr1 .filter(x => !arr2.includes(x)) .concat(arr2.filter(x => !arr1.includes(x))); //['a', 'd']
参考:SO