Recently, I've been utilizing the momentJS library to generate an array of 7 days in a week like this:
const moment = require('moment')
var startOfWeek = moment().startOf('week');
var endOfWeek = moment().endOf('week');
var days = [];
var day = startOfWeek;
while (day <= endOfWeek) {
days.push(day.format("MMMM ddd DD, YYYY"));
day = day.clone().add(1, 'd');
}
console.log(days);
The output gives me an array with the format of 7 days a week as shown below:
["December Sun 25, 2022","December Mon 26, 2022", "December Tue 27, 2022" , "December Wed 28, 2022", "December Thu 29, 2022", "December Fri 30, 2022", "December Sat 31, 2022"]
However, I am aiming for a different result structured like this:
const weekday = [
{
day: Mon,
date: 26
},
{
day: Tue,
date: 27
},
{
day: Wed,
date: 28
},
{
day: Thu,
date: 29
},
{
day: Fri,
date: 30
},
{
day: Sat,
date: 31
},
]
I am currently facing challenges in converting the data. Could someone assist me with this? Thank you!