标签:mamicode name div item java items class highlight nbsp
1:平常的操作 (直接同for循环)
这个要算6次才能算出来
2:用map去计算
let a = [{ id: ‘1‘, name: ‘1‘ }, { id: ‘2‘, name: ‘2‘ }, { id: ‘3‘, name: ‘3‘ }] let b = [{ id: ‘3‘, name: ‘3‘ }, { id: ‘1‘, name: ‘1‘ } ] let c = new Map() a.map(item => { c.set(item.id, item) }) let d = [] let e = [] let num = 0 b.map(item => { num++ if (c.has(item.id)) { d.push(item) console.log(num) } else { e.push(item) } })
这个才计算两次
标签:mamicode name div item java items class highlight nbsp
原文地址:https://www.cnblogs.com/wxydemo/p/12629631.html