Obtengo una serie de fechas en este formato.
Sat Feb 12 2022 01:00:00 GMT+0100 (West Africa Standard Time),Sun Feb 13 2022 01:00:00 GMT+0100 (West Africa Standard Time),Mon Feb 14 2022 01:00:00 GMT+0100 (West Africa Standard Time)Pero lo quiero en un formato como este.
Sat, Feb 12, 2022, Sun, Feb 13, 2022, Mon, Feb 14, 2022Este es el código que da salida a mi fecha.
function dateRange(startDate, endDate, steps = 1) { const dateArray = []; let currentDate = new Date(startDate); while (currentDate <= new Date(endDate)) { dateArray.push(new Date(currentDate)); currentDate.setUTCDate(currentDate.getUTCDate() + steps); } return dateArray; } var currD = new Date().toISOString().slice(0,10); function addDays(date, days) { var result = new Date(date); result.setDate(result.getDate() + days); return result; } const futureDate = addDays(currD, 3); const dates = dateRange(currD, futureDate); console.log(dates); alert(dates)Prueba esto
const dates = [ 'Sat Feb 12 2022 01:00:00 GMT+0100 (West Africa Standard Time)', 'Sun Feb 13 2022 01:00:00 GMT+0100 (West Africa Standard Time)', 'Mon Feb 14 2022 01:00:00 GMT+0100 (West Africa Standard Time)', ]; const formatted = dates.map((date) => new Date(date).toDateString()); console.log(formatted);