I would like the list to be sorted by the "createdAt" field by the most recent date of the chat object.
I tried to access the field with this form, but I can't get it to sort, I'm wondering if it's because of the date format it's receiving.
let sortArray = chatSalaArray.sort((a,b) => a.chat.createdAt - b.chat.createdAt)
chatSalaArray: [
{
id_user1: {
perNom: 'Hernan, Rios Valencia',
perCod: 626f14f66d157518bcb62c40,
},
id_user2: {
perNom: 'Apheli, Fabilli Da Silva',
perCod: 62096a989f4470104881266e,
},
unionfr: '626f14f66d157518bcb62c40-62096a989f4470104881266e',
_id: 6345f3245860001cb00cf65c,
chat: {
createdAt: 2022-10-11T22:50:18.493Z,
updatedAt: 2022-10-11T22:50:18.493Z,
__v: 0
}
},
{
id_user1: {
perNom: 'Mery, Carrasco Ríos',
perCod: 62203c063bc3c74128ba9516,
perNomBus: 'MeryCarrascoRíos.YFM.0'
},
id_user2: {
perNom: 'Apheli, Fabilli Da Silva',
perCod: 62096a989f4470104881266e,
},
unionfr: '62203c063bc3c74128ba9516-62096a989f4470104881266e',
_id: 6345f33e5860001cb00cf65e,
chat: {
createdAt: 2022-10-11T22:53:54.969Z,
updatedAt: 2022-10-11T22:53:54.969Z,
__v: 0
}
}
]