S
S
Sterben_082021-06-04 08:46:09
JavaScript
Sterben_08, 2021-06-04 08:46:09

How to get the next 3 days of the week?

How to get the next 3 days of the week (Monday,Tuesday,Wednesday)? It is necessary to display the current day of the week and the next two on the page. Implemented using an array:

let week = [];
    week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
        "Friday", "Saturday",
    ];
    let today = new Date();
    let day = today.getDay();
    document.querySelector('.current_day').textContent = week[day];

but the result is wrong, a day is lost.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-06-04
@Rsa97

const date = new Date();
const asWeekday = new Intl.DateTimeFormat('en-US', {weekday: 'long'});
const today = asWeekday.format(date);
date.setDate(date.getDate() + 1);
const tomorrow = asWeekday.format(date);
console.log(today, tomorrow);
// Friday Saturday

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question