showing results for - "convert a date range into an array of date in js"
Pablo
05 Apr 2017
1function dateRange(startDate, endDate, steps = 1) {
2  const dateArray = [];
3  let currentDate = new Date(startDate);
4
5  while (currentDate <= new Date(endDate)) {
6    dateArray.push(new Date(currentDate));
7    // Use UTC date to prevent problems with time zones and DST
8    currentDate.setUTCDate(currentDate.getUTCDate() + steps);
9  }
10
11  return dateArray;
12}
13
14const dates = dateRange('2020-09-27', '2020-10-28');
15console.log(dates);