有两个数组:数组1和数组2;想实现的需求:判断数组2里有没有数组1的任意一项,有则true,无则false
数组2
数组1
let arr1 = [1,2,3,4,5,6]; let arr2 = [6,7,8,9,10,11]; let result = false; for(item of arr1){ if(arr2.includes(item)){ result = true; break; } }
有没有大佬有更好的写法
var arr1 = [1,2,3,4,5,6];var arr2 = [6,7,8,9,10,11];var result = (arr1.length + arr2.length) !== Array.from(new Set([...arr1,...arr2])).length;
1.4m articles
1.4m replys
5 comments
57.0k users