How to generate such an array?

  • 0
    Hello, just starting to comprehend js. I need to generate an array of numbers 1–31 inclusive (day of the month). Using console.log, print the string $ {number} January, $ {day of the week} for each of the numbers. The day of the week January 1 must be set using a variable, that is, the program must work correctly for any day of the week from which the month begins.
    To make it work:
    January 1st, Tuesday
    Wednesday January 2nd
    January 3, Thursday
    Friday January 4th
    January 5, Saturday
    January 6, Sunday
    January 7, Monday
    etc.
    JavaScript Ivy Edwards, Feb 23, 2019

  • 1 Answers
  • 0
    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}`);
    });
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!