I am creating a calendar with JavaScript and Moment.js and would like to know how to create an array that contains all 42 days (dates) that should be displayed for the selected month.
I am using the moment getDaysInMonth() function to help me get the days in the currently selected month then looping through them pushing all of the dates to an array.
I am struggling filling in the final days of the previous month and the first few days of the next month (that you would typically see greyed out in a calendar).
Here is an example showing Week 1 and Week 6 in the array. The dots show the rest of the dates in between that can be assumed:
[new Date("2020-07-26"), new Date("2020-07-27"), new Date("2020-07-28"), new Date("2020-07-29"), new Date("2020-07-30"), new Date("2020-07-31"), new Date("2020-07-01"),................................................... new Date("2020-08-30"), new Date("2020-08-31"), new Date("2020-09-01"), new Date("2020-09-02"), new Date("2020-09-03"), new Date("2020-09-04"), new Date("2020-09-05")],