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);

 

参考:

https://www.cnblogs.com/angle-happy/p/5917109.html

http://www.jb51.net/article/48941.htm

posted @ 2018-01-17 00:44  EasonJim  阅读(2694)  评论(0编辑  收藏  举报