let arr1 = [1,2,7,4,9,5,3,2] let arr2 = [2,3,5,6] //去重利用集合,并返回数组 let uniq = [...new Set(arr1)] console.log(uniq); //求交集 let jiaoji = arr2.filter(item=>uniq.includes(item)) console.log(jiaoji) //求并集 let bingji = new Set([...arr1 , ...arr2]); console.log(bingji) //求差集 let chaji = arr2.filter(item=>!(uniq.includes(item)) ) console.log(chaji)
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/289853.html