2024年07月29日 建站教程
var arr1 = [ {name: '小白', value: 4}, {name: '小黑', value:6}, {name: '小红', value: 11}, {name: '小黑', value: 8} ];
function mergeObject(arr, name) { const result = arr.reduce((obj, item) => { if (!obj[item.name]) { obj[item.name] = 0; } obj[item.name] += item.value; return obj; }, {}); return Object.keys(result).map(name => ({ name: name, value: result[name] })); }
console.log(mergeObject(arr1))
本文链接:http://so.lmcjl.com/news/9414/