I want an array of dates starting from today to next six days, so it must contain an object representing the which day like monday.. and date in 2-dgit number
const date = new Date();
let option = {
weekday: 'long',
day: '2-digit'
};
let date_details = date.toLocaleDateString('en-US', option).split(' ');
let dataslot = [
{
day: date_details[0], //'Wednesday',
date: date_details[1] //'29'
}
];
This is an example for one day, but i expect till next 6 six days
How do i get the next six days from today in that format ?
3
Answers
The post given by jonrsharpe provides the idea on how to acheive your requirement. To be more specific, refer the code below.
To generate an array of dates starting from today to the next six days with each object representing the day of the week and the date in two-digit format, you can use the following approach:
You don’t want to create
new Date
object for each iteration. Checkout this