79569236

Date: 2025-04-11 15:44:27
Score: 1.5
Natty:
Report link

Based on @hopebordarh answer, you can also use .clone to avoid mutations on original values as following:

import moment from 'moment'

// 👉 Search period
const initialDate = moment()
const finalDate = moment().add(9, 'days')

const dateRange = [] as string[]
const dateRangeStart = initialDate.clone()

while (dateRangeStart.isBefore(finalDate)) {
  dateRange.push(dateRangeStart.toDate())
  dateRangeStart.add(1, 'days')
}
Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @hopebordarh
  • Low reputation (1):
Posted by: Gustavo - Gugabit