本文共 250 字,大约阅读时间需要 1 分钟。
const arr1 = [1,2,3]const arr2 = [3,4,5]// 1.filterconst arr = arr1.filter(el => arr2.indexOf(el) !== -1)arr// 2.利用set,遍历选择set.size()最小的,节省时间const set1 = new Set(arr1)const set2 = new Set(arr2)for(let el of set1){ if(set2.has(el)) console.log(el);}
转载地址:http://gzxzi.baihongyu.com/