So i try to loop an Array and push it into object within this code:
const past7Days = [...Array(7).keys()].map(index => {
var date = new Date();
const local = new Date();
local.setMinutes(date.getMinutes() - date.getTimezoneOffset());
local.setDate(date.getDate() - index);
return local.toJSON().slice(0, 10);
});
let data={};
let arr=[]
for (var i = 0; i < past7Days.length; i++) {
console.log(past7Days[i]);
return arr.push(data["key"] = past7Days[i])
}
what i expected is :
[{key:"date"},{key:"date2"}]
can somebody tellme where did i do wrong here
{key:"date",key:"date2"}to the console, you'll see something like{key: 'date2'}as the evaluation result. When you assign todata["key"], you overwrite any older value.key? Can you explain how that is useful? Why not an array of dates?