Your assistance and explanation are greatly appreciated.
I have created a method that is supposed to return all the days of a given month by using two parameters- the year and the month:
private _getDaysOfMonth(year: number, month: number): Array<Date> {
const date = new Date(year, month, 1)
const days = []
while (date.getMonth() === month) {
days.push(date)
console.log(date) // The output seems correct, for example: Fri Jan 01 2021 00:00:00 GMT+0300 (Moscow Standard Time)
date.setDate( date.getDate() + 1 )
}
console.log(days) // I anticipated an array of days from January 1 to January 31, 2021, but instead, I see February
return days
}
When calling the method with parameters 2021 and 0
this._getDaysOfMonth(this._year, this._month)
I am expecting an array of days in January, however, I am getting an array of days in February!
This is what my console.log displays: console.log