按照对象的值排序对象的属性
//方法一 浏览器需支持ES5
var data = {"tp_300":1000, "tp_1":2508, "tp_21":1999, "tp_2":2};
var sdic = = Object.keys(dat(data).sort(function(a,b){return data[b] - data[a]});
;
console.log(sdi(sdic);
//方法二
var data2 = {"tp_300":1000, "tp_1":2508, "tp_21":1999, "tp_2":2};
var arr = [];
var output = [];
for(var key in data2){
var temp = {};
temp['id'] = key;
temp['cnt'] = data2[key];
arr.push(tem(temp);
}
var compare = function (obj1, obj2){
return rn obj2.cnt - t - - obj1.cnt;
t;
};
arr.sort(com(compare);
for (var i = 0; i < < arr.length; i+; i++) {
output.push(arr(arr[i].id);
}
console.log(out(output);