问题 I have an array like this var temp = [{"rank":3,"name":"Xan"},{"rank":1,"name":"Man"},{"rank":2,"name":"Han"}] I am trying to sort it as follows temp.sort(function(a){ a.rank}) But its n ot working.Can anyone suggest help.Thanks. 回答1: With Array#sort, you need to check the second item as well, for a symetrical value and return a value. var temp = [{ rank: 3, name: "Xan" }, { rank: 1, name: "Man" }, { rank: 2, name: "Han" }]; temp.sort(function(a, b) { return a.rank - b.rank; }); console.log