I have an array of objects with String
values that I want to convert to Date
, but I'm getting the following error:
Uncaught SyntaxError: Unexpected token :
How should I correctly do this conversion and return the same object structure?
array = [
{
end: "2017-05-18T09:00:00.000Z",
start: "2017-05-18T06:00:00.000Z"
},
{
end: "2017-05-19T07:00:00.000Z",
start: "2017-05-19T06:00:00.000Z"
},
{
end: "2017-05-20T08:00:00.000Z",
start: "2017-05-20T07:00:00.000Z"
}
]
result = array.map((element) => {
{
end: new Date(element.end),
start: new Date(element.start),
}
})