Home > Mobile >  How to convert each of string dates, e.g., form ''2022-09-27'' to new Date('
How to convert each of string dates, e.g., form ''2022-09-27'' to new Date('

Time:09-19

how to convert the array of dates ['2022-09-27', '2022-09-26', '2022-09-29', '2022-09-28', '2022-10-01', '2022-10-02', '2022-10-03'] to new Date ('2022-09-27'),new Date('2022-09-26')

CodePudding user response:

You can create new array using map function.

const dates = ['2022-09-27', '2022-09-26', '2022-09-29', '2022-09-28', '2022-10-01', '2022-10-02', '2022-10-03'];

const new_dates = dates.map((date) => {
   return new Date(date);
});

console.log(new_dates);

  • Related