I have an array of objects of key-values in this format and I need to transform it. In each period, I have two (or more) statuses (empty or full, although there could be more). Each of these statuses has a certain number of observations (count).
//original format
const test = [
{
"count":[8,31,3],
"period":["2021-12","2022-01","2022-01"],
"status":["empty","empty","full"]
}
]
//transformation I need
output = [
{
period:"2021-12",
status:"empty",
count:8
},
{
period:"2022-01",
status:"empty",
count:31
},
{
period:"2022-01",
status:"full",
count:3
}
]
How to rearrange the format of this array in JS? I have tried using a reduce function but haven't been able to wrap my head around it.