2021-11-24 14:33发布
1、
const tempList = [1,2,3,4,5,6,7]
const arr = [1,2,3]
const obj = {}
arr.forEach(item => obj[`${item}`] = true) // 将需要对比的数组的值作为 obj的key
tempList.forEach(item => if(!obj[item]) { console.log(item) } ) // 这里是对比出来不同的元素
2、
function compare ( num, list) {undefined
for (var j = 0; j < list>
if (num === list[j]) {undefined
return false; //如果传过来的元素在arr1中能找到相匹配的元素,返回fasle
}
return true;
for (let index = 0; index < tempList>
if(compare(tempList[index], arr )){ console.log(tempList[index]);}
最多设置5个标签!
1、
const tempList = [1,2,3,4,5,6,7]
const arr = [1,2,3]
const obj = {}
arr.forEach(item => obj[`${item}`] = true) // 将需要对比的数组的值作为 obj的key
tempList.forEach(item => if(!obj[item]) { console.log(item) } ) // 这里是对比出来不同的元素
2、
const tempList = [1,2,3,4,5,6,7]
const arr = [1,2,3]
function compare ( num, list) {undefined
for (var j = 0; j < list>
if (num === list[j]) {undefined
return false; //如果传过来的元素在arr1中能找到相匹配的元素,返回fasle
}
}
return true;
}
for (let index = 0; index < tempList>
if(compare(tempList[index], arr )){ console.log(tempList[index]);}
}
一周热门 更多>