I tried to make an array which contains data of 1 week, but can't figure something else than this
Should I do a for loop or something? I am quite noob, so I hardcode it to make it work. The code does work but it is kinda slow and weird, I think there is another solution to this, help me please lol
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
let today, date;
today = new Date();
date = new Date(today);
const one = new Date();
one.setDate(date.getDate() + 1);
const two = new Date();
two.setDate(date.getDate() + 2);
const three = new Date();
three.setDate(date.getDate() + 3);
const four = new Date();
four.setDate(date.getDate() + 4);
const five = new Date();
five.setDate(date.getDate() + 5);
const six = new Date();
six.setDate(date.getDate() + 6);
const dataday = [
{
day: days[today.getDay()],
num: today.getDate(),
date:
today.getDate() + "-" + today.getFullYear() + "-" + today.getMonth(),
selected: false,
},
{
day: days[one.getDay()],
num: one.getDate(),
date: one.getDate() + "-" + one.getFullYear() + "-" + one.getMonth(),
selected: false,
},
{
day: days[two.getDay()],
num: two.getDate(),
date: two.getDate() + "-" + two.getFullYear() + "-" + two.getMonth(),
selected: false,
},
{
day: days[three.getDay()],
num: three.getDate(),
date:
three.getDate() + "-" + three.getFullYear() + "-" + three.getMonth(),
selected: false,
},
{
day: days[four.getDay()],
num: four.getDate(),
date: four.getDate() + "-" + four.getFullYear() + "-" + four.getMonth(),
selected: false,
},
{
day: days[five.getDay()],
num: five.getDate(),
date: five.getDate() + "-" + five.getFullYear() + "-" + five.getMonth(),
selected: false,
},
{
day: days[six.getDay()],
num: six.getDate(),
date: six.getDate() + "-" + six.getFullYear() + "-" + six.getMonth(),
selected: false,
},
];
console.log(dataday);