Number For Each Day Of The Week

[Solved] Number For Each Day Of The Week | Shell - Code Explorer | yomemimo.com
Question : number for each day of the week

Answered by : crowz

function getWeekdayCounts(year, month) { const numDaysInMonth = new Date(year, month, 0).getDate(); const counts = [0, 0, 0, 0, 0, 0, 0]; for (let day = 1; day <= numDaysInMonth; day++) { const date = new Date(year, month - 1, day); const dayOfWeek = date.getDay(); counts[dayOfWeek]++; } return counts;
}
const date = new Date();
const counts = getWeekdayCounts(date.getFullYear(), date.getMonth() + 1);
console.log(counts)

Source : | Last Update : Sun, 19 Mar 23

Answers related to number for each day of the week

Code Explorer Popular Question For Shell