the below code creates the leaderboard for my completed game, the only thing that I can't get it to do is automatically sort the score high to low. I think I need to put the objects into an array and then sort them, just not sure how.
function createLeaderboard() {
var html;
html = "<table>";
html += "<tbody>";
html += "<th>Username</th>";
html += "<th>Rank</th>";
html += "<tr>";
for(var val in localStorage){
if (localStorage.getItem(val) !== null && localStorage.getItem(val) !== localStorage.getItem('UsrLoggedIn')){
var rankData = $.parseJSON(localStorage.getItem(val));
//console.log(rankData); This will allow you to see the rank data object in your console
$(rankData).each(function() {
html += "<td>" + rankData.username + "</td>";
html += "<td>" + rankData.rank + "</td> </tr>";
});
}
}
html += "</tbody>";
html += "</table>";
$('#rank').append(html);