按降序排序json属性

时间:2014-05-24 17:04:26

标签: json

我有以下json,如何按DESC顺序对“c”值进行排序?

[{"id":"2","val":"2pm.com","c":"4"}, 
{"id":"2","val":"Adidas","c":"2"},
{"id":"2","val":"AJ Morgan","c":"2"},
{"id":"2","val":"Alfio Raldo","c":"3"},
{"id":"1","val":"ASOS","c":"112"},
{"id":"2","val":"ASOS","c":"34"},
{"id":"2","val":"ASOS Curve","c":"39"},
{"id":"2","val":"Baby Be Dazzled","c":"13"}]

我使用PHP和ajax

1 个答案:

答案 0 :(得分:1)

你可以在JS中做点什么,

arr.sort(compare);

function compare(obj1, obj2) {
    return obj1.c - obj2.c;
}

console.log(arr);

Fiddle