Skip to content
Advertisement

Sorting a array based on a specific value

Hi I’m working on a game application. The schema of the game database looks like this

JavaScript

Here is an example snippet. I would like to sort the json array based on the score and extract the top 10(if any).

JavaScript

I’m having trouble sorting this array based on the userScore so that I could display the top 10 on the leaderboards. Any help would be greatly appreciated.

Advertisement

Answer

try it for sort by number:

JavaScript

in your case:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement