const array1 = [1, 2, 3, 4]; const array2 = [3, 4, 5, 6];
const filteredArray = array1.filter(value => !array2.includes(value)); console.log(filteredArray); // [1, 2,]
// 或者使用下面的代码:
const array1 = [1, 2, 3, 4]; const array2 = [3, 4, 5, 6];
const filteredArray = array1.filter(function(value) { return array2.indexOf(value) === -1; });
console.log(filteredArray); // [1, 2,]
下一篇:比较两个数组的差异