I'm sorting the keys in the object:
My object:
data = {AAA: 1, BBB: 2, CCC: 55, VVV: 33, FFF:44}
I'm using the following code to sort:
Object.fromEntries(Object.entries(data).sort(([,v1], [,v2]) => +v2 - +v1))
however it outputs:
{CCC: 55, FFF: 44, VVV: 33, BBB: 2, AAA: 1}
I want to sort the keys in the object which should result:
{AAA: 1, BBB: 2, CCC: 55, FFF: 44, VVV: 33}
and if I try to change the sorting order, still gives results based on the count and not based on the key:
Object.fromEntries(Object.entries(data).sort(([,v1], [,v2]) => +v1 - +v2))
how can I make the above code work for both sorting value and sorting keys of an object?