I have the following code which is designed to populate an array with the next n dates for a specific day of the week. Unfortunately it is only ever using the same date and I am unsure why. Could you advise as to how I could overwrite the variable nextFriday each iteration:
Code: Select all
var date = new Date();
var day = date.getDay();
var normalizedDay = (day + 2) % 7;
var daysForward = 7 - normalizedDay;
var nextFriday = new Date(+date + (daysForward * 24 * 60 * 60 * 1000));
Code: Select all
var availableDates = [];
availableDates.push(nextFriday);
var i = 0;
while (i < 8){
nextFriday.setDate(nextFriday.getDate() + 7);
availableDates.push(nextFriday);
i++
}
Alex