Thank you for your response. I still get the same issue, event though I corrected the code

function getAllSameWeekdaysForPeriod(startDateInput, periodInMonths) {
    const resultDates = [];

    const startDate = new Date(startDateInput);
   
    const endDate = new Date(startDate);
    endDate.setUTCMonth(startDate.getUTCMonth() + periodInMonths); // Set the end date

    // Collect all dates with the same weekday within the period
    let currentDate = new Date(startDate);
   
    while (currentDate < endDate) {
        resultDates.push(new Date(currentDate));
        currentDate.setUTCDate(currentDate.getUTCDate() + 7); // Move to the next week
    }

    return resultDates;
}

// Example usage:
const date = new Date('start-date:formatted as 2024-10-23T22:13:50.865Z');

return getAllSameWeekdaysForPeriod(date, 1);