I have an object like this :
{
"25276234": {
"id": "25276234",
"title": "new",
},
"4c57f8b9": {
"id": "4c57f8b9",
"title": "aa",
},
"c5353527": {
"id": "c5353527",
"title": "1",
},
"76517feb": {
"id": "76517feb",
"title": "bs",
},
"b6458d0c": {
"id": "b6458d0c",
"title": "new doc",
},
"d8ca47f7": {
"id": "d8ca47f7",
"title": "AAAA",
},
"2a72cba8": {
"id": "2a72cba8",
"title": "abcd",
},
"73694f31": {
"id": "73694f31",
"title": "A",
}
}
My aim is to sort it based on the title and the final sorted result should be an object of this format only and not an array.
I have tried several ways like -
const sorted = {};
Object
.keys(data).sort((o1,o2) => {
return data[o1].title - data[o2].title;
})
.forEach((key) => {
sorted[key] = data[key];
});
But it is not being sorted for some reason. What am I doing wrong and what is the solution?