I have an object which looks like the following
{
"8 am": 2,
"11 am": 6,
"12 pm": 3,
"5 pm": 7,
"1 pm": 0
}
I am using the code below to sort the object using keys.
const ordered: any = {};
Object.keys(groupedData).sort().map((key) => {
ordered[key] = groupedData[key];
});
I get a result as follows
{
"1 pm": 0,
"8 am": 2,
"11 am": 6,
"12 pm": 3,
"5 pm": 7,
}
However what I require is something like this
{
"8 am": 2,
"11 am": 6,
"12 pm": 3,
"1 pm": 0,
"5 pm": 7
}
How can I achieve this in typescript or javascript. Solutions with plugins are also welcome.