标签:不同 name log color OLE class 数组 res 判断
已知数组 arr1和arr2,需求:判断arr1中与arr2中不同的数
let arr1 = [ { id: 1, name: 1, }, { id: 2, name: 2, }, { id: 3, name: 3, }, { id: 3, name: 3, }, ] let arr2 = [ { id: 4, name: 4, }, { id: 5, name: 5, }, { id: 6, name: 6, }, { id: 1, name: 1, }, { id: 7, name: 7 } ]
let obj = {}; let arrResult = []; arr2.forEach((item, index) => { obj[item.id] = true }) // console.log(obj,‘obj123‘) arr1.forEach((item, index) => { if (!obj[item.id]) { arrResult.push(item.id) } })
标签:不同 name log color OLE class 数组 res 判断
原文地址:https://www.cnblogs.com/0520euv/p/11741177.html