A problem about refactoring arrays

there is the following array:

const fData = [

{ownerName: "a", type: "1", total: 85}

{ownerName: "a", type: "2", total: 22}

{ownerName: "b", type: "1", total: 11}

{ownerName: "b", type: "2", total: 11}

{ownerName: "c", type: "1", total: 121}

{ownerName: "c", type: "2", total: 11}
]

want to reconstitute the following array:

[{ownerName: "a", "1": 85, "2": 22}

{ownerName: "b", "1": 11, "2": 11}

{ownerName: "c", "1": 121, "2": 11}

I am currently working on the following code:

let newName = map(uniq(ownerName), (item) => {
            return {
                ownerName: item,
            };
        });
        let newType = map(uniq(type), (item) => {
            return {
                type: item,
            };
        });

where uniq and map are libraries of referenced third-party lodash.
I don"t know how to write it down. For guidance, thank you

Mar.04,2021

set a map = {}
traversal fData
merge map [ownerName] information
finally convert map to an array


const fData = [
  { ownerName: "a", type: "1", total: 85 },
  { ownerName: "a", type: "2", total: 22 },
  { ownerName: "b", type: "1", total: 11 },
  { ownerName: "b", type: "2", total: 11 },
  { ownerName: "c", type: "1", total: 121 },
  { ownerName: "c", type: "2", total: 11 },
]

let tmpObj = {}
for (let item of fData) {
  if (!tmpObj[item.ownerName]) {
    tmpObj[item.ownerName] = {}
  }
  tmpObj[item.ownerName][item.type] = item.total
}
let result = Object.entries(tmpObj).map(item => {
  item[1]['ownerName'] = item[0]
  return item[1]
})


----

typetotal?

let tmpObj = fData.reduce((accumulator, currentValue, currentIndex, array) => {
  if (!accumulator[currentValue.ownerName]) {
    accumulator[currentValue.ownerName] = {}
  }
  if (!accumulator[currentValue.ownerName][currentValue.type]) {
    accumulator[currentValue.ownerName][currentValue.type] = 0
  }
  accumulator[currentValue.ownerName][currentValue.type] += currentValue.total
  return accumulator
}, {})
let result = Object.entries(tmpObj).map(item => {
  item[1]['ownerName'] = item[0]
  return item[1]
})
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-1b3ade2-407d5.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-1b3ade2-407d5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?