我是靠谱客的博主 痴情背包,这篇文章主要介绍js字符串的字典序_js 字典排序,现在分享给大家,希望可以做个参考。

var dic = {

2: {"score": 20},

1: {"score": 25},

3: {"score": 15},

4: {"score": 60},

}

console.log("输出最初的字典元素: ");

for(var key in dic){

console.log("key: " + key + " ,value: " + dic[key]);

}

console.log("字典元素按key值排序: ");

var res = Object.keys(dic).sort();

for(var key in res){

console.log("key: " + res[key] + " ,value: " + dic[res[key]]);

}

console.log("字典元素按value值排序: ");

var res2 = Object.keys(dic).sort(function(a,b){ return dic[a]["score"]-dic[b]["score"]; });

for(var key in res2){

console.log("key: " + res2[key] + " ,value: " + dic[res2[key]]);

}

最后

以上就是痴情背包最近收集整理的关于js字符串的字典序_js 字典排序的全部内容,更多相关js字符串的字典序_js内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部