我试图弄清楚如何按该数组中的对象对我的数组进行排序。在此示例中,我希望能够按玩家姓名或玩家分数对数组进行排序。
var topPlayers = new Array();
$(".player").each( function(i) {
topPlayers[i] = {};
topPlayers[i]["name"] = $(this).children(".name").text();
topPlayers[i]["score"] = $(this).children(".score").text();
});
topPlayers.sort(function(a.name,b.name){return a.name-b.name}); //This is the line of code I can't figure...