取数组差集(数组元素为基本类型)

4年以前  |  阅读数:268 次  |  编程语言:JavaScript 
//数组arr1相对于arr2所没有的

const arr1 = [1, 2, 3, 4, 5, 8, 9]
const arr2 = [5, 6, 7, 8, 9];
const diff = arr1.filter(item => !new Set(arr2).has(item))
console.log(diff) //[ 1, 2, 3, 4 ]

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8