js如何判断两个数组是否有重复的元素(转)()

原文:

https://www.yisu.com/zixun/730087.html
  • js如何判断两个数组是否有重复的元素
let a=[1, 2, 3];
let b=[3, 5, 2];
newA = new Set(a);
newB = new Set(b);
let intersectionSet = new Set([...newA].filter(x => newB.has(x)));
console.log(intersectionSet);
let arr = Array.from(intersectionSet);

console.log(arr);
if(arr==[]){
console.log("两个数组没有重复元素");
}else{
console.log("两个数组有重复元素");
}
————————

原文:

https://www.yisu.com/zixun/730087.html
  • js如何判断两个数组是否有重复的元素
let a=[1, 2, 3];
let b=[3, 5, 2];
newA = new Set(a);
newB = new Set(b);
let intersectionSet = new Set([...newA].filter(x => newB.has(x)));
console.log(intersectionSet);
let arr = Array.from(intersectionSet);

console.log(arr);
if(arr==[]){
console.log("两个数组没有重复元素");
}else{
console.log("两个数组有重复元素");
}