JavaScript对JSON数据进行排序
var ajson= { "result":[ { "cid":1, "name":"aaa", "price":1000 },{ "cid":2, "name":"bbb", "price":150 },{ "cid":3, "name":"ccc", "price":200 },{ "cid":4, "name":"ddd", "price":1500 },{ "cid":5, "name":"eee", "price":1100 } ], "totalCount":5 } function sortJ(a,b){ return a.price-b.price; }; var data=ajson.result.sort(sortJ); console.log(data);
参考: