Hello everyone, I am faced with an array of objects that I need to destructure. Below is a snippet from the array:
[
{
"Area": "Werk Produktivität [%] - Target",
"Jan": 86.21397507374327,
"Feb": 86.0570021973368,
"Mrz": 88.70898346258058,
"Apr": 85.29801908413164,
"May": 85.07431241640211
},
{
"Area": "Werk Produktivität [%] - Actual",
"Jan": 84.17054711398421,
"Feb": 83.80826026601528,
"Mrz": 84.11553769971036,
"Apr": 83.76460916731,
"May": 82.69773876702813
}
]
My goal now is to split the array into the following sections:
[
{
"Area": "Werk Produktivität [%] - Target",
"Jan": 86.21397507374327
},
{
"Area": "Werk Produktivität [%] - Target",
"Feb": 86.0570021973368,
},
...
My initial approach was to utilize the ...rest
parameter in this way, but it only retrieves the last 5 items of the array. Note that 'obj' represents the object excerpt displayed above.
const fn = ({ Area, ...rest }) =>
Object.values(rest)
.map(Month => ({
Area,
Month
}))
})
const result = fn(obj)