取2个数组的交集(数组元数为基本类型)

4年以前  |  阅读数:271 次  |  编程语言:JavaScript 
const arr1 = [1, 2, 3, 4, 5 , 8 ,9],arr2 = [5, 6, 7, 8, 9];

const intersection = arr1.filter(function (val) { return arr2.indexOf(val) > -1 })
console.log(intersection) //[5, 8, 9]

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8