JavaScript对象数组排序,使用了Array.prototype.sort(),具体代码如下:
<script>
var sortArr = [
{ name: "Robin Van PurseStrings", age: 30 },
{ name: "Theo Walcott", age: 24 },
{ name: "Bacary Sagna", age: 28 }
].sort(function(obj1, obj2) {return obj2.age - obj1.age;});
for(var i=0; i<sortArr.length;i++) {
alert(sortArr[i].name);
}
</script>
更多信息请查看IT技术专栏