javascript 集合 交集 并集 差集
作者:互联网
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)
标签:console,log,并集,javascript,差集,item,let,arr2,uniq 来源: https://www.cnblogs.com/qutao125/p/16700687.html