I have below code of data. It is an object and each key has a date to it. There are properties Open and Closed within it. If Closed is 0, then that property is not present.
let data = {
"2021-09-06": {
"Open": 24
},
"2021-09-07": {
"Open": 80,
"Closed": 14
},
}
I want to achieve the following
let res = [
{ "date": "2021-09-06", "Open": 24, "Closed": 0 },
{ "date": "2021-09-07", "Open": 80, "Closed": 14 },
]
Can someone please let me know how to achieve this. I have tried this way but i dont get date property within the object as i want.
Object.entries(data).map((e) => ( { [e[0]]: e[1] } ));