我有这样的人
hash['a'] = ["a","b","c","d","e"];
hash['b'] = ["a","b","c"];
hash['k'] = ["q","b"];
Math.max(Object.keys(hash).map(function(key){
return hash[key].length;
});
它返回5,但是我想同时获得哈希键'a'
。
有可能吗?
这符合您的要求吗?
我在这里使用sort
而不是Math.max
来找到最大值
var hash = {};
hash['a'] = ["a", "b", "c", "d", "e"];
hash['b'] = ["a", "b", "c"];
hash['k'] = ["q", "b"];
var result = Object.keys(hash)
.map(function(key) {
return {[key]: hash[key].length};
}).sort(function(a, b){
return a.key > b.key
})[0]
console.log(result);