I need to return an array containing a Date object for each day remaining in the month, for a given Date.
I need a for
loop that creates new Date()
You can use the getTime
and setTime
methods of the Date object to advance one day at a time.
var days = [];
var now = new Date();
var day = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0);
while (day.getMonth() === now.getMonth()) {
days.push(day);
// Go to the next day
day = new Date(day.getTime() + 86400000); // There are 86400000 milliseconds in a day
}