I have an object that gives counts per day, and the date is the key. I would like to create a new object that has two properties (day and count) that uses the key:value pair.
This is the input format I have, and the structure I'm trying to achieve:
const have = {
"2022/01/01":0,
"2022/01/02":10,
"2022/01/03":12,
"2022/01/04":6,
"2022/01/05":8
};
const want = [
{day:"2022/01/01",count:0},
{day:"2022/01/02",count:10},
{day:"2022/01/03",count:12},
{day:"2022/01/04",count:6},
{day:"2022/01/05",count:8},
];
I've only gotten as far as printing each key and value to the log, but unsure how I can add these to a new object
let want = new Object();
Object.keys(have).forEach(function (key) {
console.log(key);
console.log(have[key]);
});
array.map()object's keysObject.keys(have).map(key => { return { day: key, count: have[key] } })