I have a data which consists of accessTime as a key which is actually a date in strong format i want to sort that accesstime in desending order.
[
0: {
accessTime: "2019-12-05 03:11:11"
id: "CBA567E1-8B8B-A88A-7A21-AD30C140502D"
name: "test proc"
type: "0"
version: "1"
},
{
accessTime: "2019-12-05 03:12:35"
id: "87DB7B7A-37C8-9BD7-D12C-D5548E402B13"
name: "testProcess88"
type: "0"
version: "1"
},
{
accessTime: "2019-12-05 03:12:48"
id: "73005C00-9FEF-762D-0FC5-D554C27B7A22"
name: "testprocess89"
type: "0"
version: "1"
}
]
Data is array of an object i have to sort this data on the basis of accessTime field in desending order please can some one suggest some function or so.
I have tried with this code but it is not working for me :
sort(arr, key) {
return arr.sort((a, b) => (a[key].toLowerCase() > b[key].toLowerCase()) ? 1 : ((b[key].toLowerCase() > a[key].toLowerCase()) ? 0 : -1));
}
please help