I'm trying to use destructuring but it seems I'm doing wrong the assignment.
Is it possible to do it like this?
let fields = ["FASE", "BAWTOM_1"]
let object = {}
const d = await getData();
const count = d.reduce((acc, elem) => {
({ [fields[0]], [fields[1]] } = elem)
return {...acc, [ fields[1] ]: [...(acc[ fields[1] ] || []), {fase: fields[0] }]};
}, {});
I'm stack on the ({ [fields[0]], [fields[1]] } = elem)
that I'm not able to get it work
any help is much appreciated
elem is somthing like this, with much more items
var elem = [
{"FASE": "2",
"BAWTOM_1": "1",
"BA_SP_1": "0",
"BA_SP_2": "0",
"BA_SP_3": "0",
},
{"FASE": "1",
"BAWTOM_1": "2",
"BA_SP_1": "1",
"BA_SP_2": "0",
"BA_SP_3": "0",
},
{"FASE": "1",
"BAWTOM_1": "1",
"BA_SP_1": "0",
"BA_SP_2": "1",
"BA_SP_3": "0",
},
{"FASE": "2",
"BAWTOM_1": "4",
"BA_SP_1": "1",
"BA_SP_2": "0",
"BA_SP_3": "1",
}
]