js数组中对象怎么合并
var list=[{id:1,number:2,title:2},{id:1,number:3,title:2}]
如果数组中id和title的值相同,数组中两个对象合并,number值相加,怎么实现
最终得到[{id:1,number:5,title:2}]
```
var list=[{id:1,number:2,title:2},{id:1,number:3,title:2}]
function merge (list) {
  let result = []
  let cache = {}
  list.forEach(item => {
    let key = `id:${item.id},title${item.title`
    let index = cache[key]
    if (index !== undefined) {
      result[index].number += item.number
    } else {
      result.push(Object.assign({}, item))
      cache[key] = result.length - 1
    }
  })
  return result
}

merge(list)
```