I'm trying to sort the following JSON with my jquery and make a leader board out of their 'money' I want the #1 leader to be the one with the most money and the last place person the one with the least. I've tried several ways of doing this including a sort function but I can't seem to get it to work. Can you explain the best way of doing this?
{
id: "3",
username: "test3",
money: "500",
state_id: "0",
state_name: "none",
state_abbrev: "none",
bets_amount_total: 0,
bets_amount_won: 0,
bets_amount_lost: 0
},
{
id: "4",
username: "johnny",
money: "500",
state_id: "0",
state_name: "none",
state_abbrev: "none",
bets_amount_total: 0,
bets_amount_won: 0,
bets_amount_lost: 0
},
here's my code:
getLeaders().done(function(results){
$.each(results, function(i, leaderStats){
var leaderUser = leaderStats.username;
var money = leaderStats.money
$('#leader-container').append('\
<div>\
<div class="leaderboard-rank">rank</div>\
<div class="leaderboard-name">' + leaderUser +'</div>\
<div class="leaderboard-score">'+ money +'</div>\
</div>\
');
});
});