I have a JSON file and I need to retrieve only the items with the ten highest scores:
My data:
{
"movies" : {
"eraserhead" : {
"full_title" : "Eraserhead",
"votes": 50
},
"psycho" : {
"full_title" : "Psycho",
"votes" : 90
}
}
}
etc, etc for a list of about 50 – 100.
I know I can iterate through and build a list, but I was curious if there’s any less processor-intensive way to filter these results based on that property (movies[title].votes).
Any help would be greatly appreciated, thank you.
The simplest would be to make an array, to sort the array and to take the first 10 elements.
Demonstration (open the console)