I would appreciate your help or idea how to sort array of object in ascending order by first value.
This is array
[{"0":"yanni"},
{"1150":"finally"},
{"852":"discovered"},
{"59":"what"},
{"30064":"had"},
{"397":"really"},
{"3100":"happened"},
{"3":"to"},
{"0":"skura"},
{"7523":"lets"},
{"6550":"try"},
]
and I want to be sorted by first number like:
[{"0":"yanni"},
{"0":"skura"},
{"3":"to"},
{"59":"what"},
.....
]
I tried like this
const keys = Object.keys(sentenceFreq);
console.log("key",keys)
const valuesIndex = keys.map((key) => ({key, value: sentenceFreq[key]}));
valuesIndex.sort((a, b) => b.value - a.value); // reverse sort
const newObject = {};
for (const item of valuesIndex) {
newObject[item.key] = item.value;
}
console.log("test", newObject);
but they are sorted only by key values...
Any help is appericated. Thank you!