I got an array from a CMS that is poorly formatted which I want to reformat to an array of objects.
let daysOffArray = ["2022-08-22, 08:00 - 14:00","2022-08-23, 08:00 - 13:00"];
Expected result after separating the array:
let daysOff = [{
date: "2022-08-22",
time: 08:00 - 14:00
},
{
date: "2022-08-23",
time: 08:00 - 13:00
}];
How can I separate the array for each second comma and then separate the two new arrays after each comma?
>Solution :
let daysOffArray = ["2022-08-22, 08:00 - 14:00","2022-08-23, 08:00 - 13:00"];
let daysOff=[]
daysOffArray.map((item)=>{
daysOff.push({date:item.split(",")[0],time:item.split(",")[1]})
})
console.log(daysOff)