How do I sort this kind of map using the field lastSeen
var clients = new Map();
clients.set("BOJ_iPWtI7jVvG_pAAAH", {name: "John", lastSeen: 1608192766697});
clients.set("cShpndAsircj4_P4AAAN", {name: "Doe", lastSeen: 1608192862339});
How do I sort this clients map using lastSeen.
I have tried like this:
var sortedClients = new Map([...clients.entries()].sort((a,b)=>b.lastSeen - a.lastSeen));
but it is not working so I know I am not doing the right thing.
aandbvalues inside the compareFunction.entriesreturns an array of key-value pairs. So,awill be something like:["BOJ_iPWtI7jVvG_pAAAH", {name: "John", lastSeen: 1608192766697}]