Json array merges the same key values and adds value

data are as follows

arr = [{name: "", value: 3},{name: "", value: 3},{name: "", value: 2}]
Mar.09,2021

function trans (arr) {
  let obj = {}
  let result = []
  arr.forEach(({name, value}) => {
    let cur = obj[name]
    if (cur) {
      let index = cur.index
      result[index].value += value
    } else {
      let index = result.length
      obj[name] = {
        name,
        index
      }
      result.push({name, value})
    }
  })
  return result
}
var arr = [{name: "", value: 1},{name: "", value: 2},{name: "", value: 3},{name: "", value: 2}]
trans(arr)

use loops

.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e8a7-41462.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e8a7-41462.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?