Hello everyone, I hope you can help me out with this issue. I have been struggling for hours trying to sort my array of objects in JavaScript based on a specific property, but I just can't seem to get it right.
I have referred to some of the top posts on Stack Overflow and tried a few different solutions, but none of them have worked for me. I want to sort my array of objects by the "horaInicial" property, which contains an ISO 8601 string.
Array(3)
0: Appointment
area: "S. Eter"
data: "2019-05-23T12:40:55.155+01:00"
description: "Sprint CS WEB"
horaFinal: "2019-05-21T11:40:59.028Z"
horaInicial: "2019-05-21T11:40:59.028Z"
id: 17
__proto__: Object
1: Appointment
area: "S. Confiança"
data: "2019-05-23T12:40:55.155+01:00"
description: "AR"
horaFinal: "2019-05-21T16:45:15.448+01:00"
horaInicial: "2019-05-21T16:00:15.448+01:00"
id: 18
__proto__: Object
2: Appointment
area: "djdndjsnsnsnzznj"
data: "2019-05-23T11:18:24.596+01:00"
description: "xbxnxnsnsjsjdjdkssjdjsjsk"
horaFinal: "2019-05-22T10:42:46.770Z"
horaInicial: "2019-05-22T11:41:46.769+01:00"
id: 23
__proto__: Object
Despite trying different sorting functions like the one below, the array remains unchanged:
this.appointments.sort(function(a, b) {
var textA = a.horaInicial.toUpperCase();
var textB = b.horaInicial.toUpperCase();
return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;
});
console.log(this.appointments);
I am clearly missing something here. Can anyone point me in the right direction?