How do I make array of object value into object property? I want to turn this
const array = [
{
"age_group": [
{
"range": "0-20",
"total_count": 100
},
{
"range": "21-30",
"total_count": 200
},
],
"machine": {
"name": "SK2DS0011",
}
}
]
into this
[{name: "SK2DS0011", "0-20": 100, "21-30": 200}]
I'm stuck at using reduce.
temp_arr = ori.reduce((accum, arr, i) => {
return accum['abc'] = arr.age_data.map(o => ({[o.range]: o.count}))
},{})
Maybe I'm using map wrong within my reduce.