1:方案1:
let result = []
data.reduce((result, item) => {
const { source, target, value } = item;
const tmp = result.get(`${source}|${target}`) || {};
result.set(`${source}|${target}`, { ...tmp, value: value + (tmp.value || 0) });
return result
}, new Map()).forEach((value, key) => {
[source, target] = key.split( "|" )
result.push( { source,target, value } )
})
2:方案二
// let newArr = []
// data.forEach(el => {
// const result = newArr.findIndex(ol => { return el.source === ol.source && el.target === ol.target })
// if (result !== -1) {
// newArr[result].value = newArr[result].value + el.value
// } else {
// newArr.push(el)
// }
// })