Answer the question
In order to leave comments, you need to log in
How to generate an array of days of the week for a given month?
I need to generate an array of numbers 1-31 inclusive (days of the month). Output using console.log for each of the numbers the string ${date} of January, ${day of the week}. The day of the week on January 1 must be specified using a variable, that is, the program must work correctly for any day of the week on which the month begins.
To get:
January 1, Tuesday
January 2, Wednesday
January 3, Thursday
January 4, Friday
January 5, Saturday
January 6, Sunday
January 7, Monday
, etc.
Answer the question
In order to leave comments, you need to log in
const array = [];
for (let i = 1; i < 32; i++){
array.push(i);
}
array.forEach(e => {
const date = new Date(2020, 0, e);
const day = new Intl.DateTimeFormat('ru-RU', { weekday: 'long'}).format(date);
console.log(`${e} января, ${day}`);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question