I'm trying to figure out how to order an array which includes Date objects inside.
Here my array Appointment[]
is below(contains 3 objects)
0: {id: 36, appointmentDate: "2019-12-27T10:28:15"}
1: {id: 57, appointmentDate: "2020-01-03T08:29:25"}
2: {id: 58, appointmentDate: "2020-01-15T15:45:19"}
Here's the method I tried to implement but didn't work it says
a.appointmentDate.getTime is not a function
if(param === 'a'){
return value.sort((a, b) => { return a.appointmentDate.getTime() - b.appointmentDate.getTime() });
}
Here also another approach didn't work either below says
The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type
if(param === 'a'){
return value.sort((a, b) => { return new Date(a.appointmentDate) - new Date(b.appointmentDate});
}