I'm trying to insert events into a calendar. the problem is my events are structured like this: xx/xx/xxxx
and the calendar uses another format
xx-xx-xxxx
. How do I make this transformation ?
I have transformed the dates from JSON format to a string but I can't change the /
into -
.
data.forEach(function (element) {
let date = new Date(element.sessionDate)
datesArr.push(date.toLocaleDateString())
})
console.log(datesArr)
And now my array looks like this:
0: "12/24/2018"
1: "12/27/2018"
2: "1/3/2019"
3: "1/3/2019"
4: "1/7/2019"
My expected result for the calendar to receive the events should be: ['2019-03-04', '2019-03-08', '2019-03-12', '2019-03-15']
.