如何转换此js对象
var obj1 = {"user1":28, "user2":87, "user3":56};
进入一个字符串数组,按值排序,如下所示:
["user2","user3","user1"]
答案 0 :(得分:10)
使用此:
var obj1 = {"user1":28, "user2":87, "user3":56};
var a = Object.keys(obj1).sort(function(x,y){return obj1[y]-obj1[x]})
console.log(a);
输出:
["user2", "user3", "user1"]