对象 替换为相同的key 并进行相加

在这里插入图片描述

changeLAN(data) {
    let name = JSON.parse(JSON.stringify(data).replace(/局域网/g,"北京"));
    let a = [];
    let result = {};
    name.forEach(e => {
      if (result[e.key]) {
        result[e.key] += e.doc_count
      } else {
        result[e.key] = e.doc_count
      }
    })
    for (const key in result) {
      if (result.hasOwnProperty(key)) {
        const element = result[key];
        a.push({
          key: key,
          doc_count: element
        })
      }
    }
    return a
  }

猜你喜欢

转载自blog.csdn.net/weixin_43271750/article/details/84394443