Answer the question
In order to leave comments, you need to log in
How to sort an object?
There is an object:
{
"10": {
"name": "The Name",
"count": "4"
},
"9": {
"name": "Some name",
"count": "7"
}
...
"1": {
"name": "Bla bla",
"count": "6"
}
}
Answer the question
In order to leave comments, you need to log in
Make an array out of the object and sort it as you need:
Object.entries(data).map(([ key, val ]) => ({ ...val, id: key })).sort((a, b) => b.id - a.id)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question