<script> //测试方法 var a = [ {name:‘hdj‘, age:128}, {name:‘hdj1‘, age:28}, {name:‘hdj1‘, age:78}, {name:‘yim‘, age:125} ]; //排序 a.sort(function(a,b){ return a["age"]-b["age"]; }); console.log(a); </script>
时间: 2024-10-09 23:01:55
<script> //测试方法 var a = [ {name:‘hdj‘, age:128}, {name:‘hdj1‘, age:28}, {name:‘hdj1‘, age:78}, {name:‘yim‘, age:125} ]; //排序 a.sort(function(a,b){ return a["age"]-b["age"]; }); console.log(a); </script>