const month = 'January'
const year = 2020
// Какой-то код
console.log(object)
/*
{
"Monday": [4, 5, 6 ,7]
"Tuesday": [8, 9, 10, 11]
...
} */
function getDatesGroupedByWeekday(year, month) {
const d = new Date(`${month} 1, ${year}`);
const iMonth = d.getMonth();
const result = {};
while (d.getMonth() === iMonth) {
const date = d.getDate();
const weekday = d.toLocaleString('en-US', { weekday: 'long' });
(result[weekday] = result[weekday] ?? []).push(date);
d.setDate(date + 1);
}
return result;
}