博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
4.利用filter和set求两个数组交集的通用方法
阅读量:3956 次
发布时间:2019-05-24

本文共 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/

你可能感兴趣的文章