I have to get highest keys with values in javascript object
var obj1 = {a: 1, b: 3, c: 2, d: 4};
var obj2 = {a: 1, b: 3, c: 2, d: 3};
I tried these codes code1
var max = Object.keys(r).reduce(function(a, b){ return r[a] > r[b] ? a : b });
code2
var max = _.max(Object.keys(obj), function (o) {return obj[o];});
code3
var max = Math.max.apply(null,Object.keys(obj).map(function(x){ return obj[x] }));
console.log(Object.keys(obj).filter(function(x){ return obj[x] == max; })[0]);
each code work ok in case of obj1, returns d because it's with max value 4 but in case of obj2 not return value according to my requirement it return only one key but I need all keys with highest values in case of obj2 requires the b & d because they both are highest value 4
Thanks Dinesh