8
Let’s say I have the following object:
var obj = {"frutas": 50, "vegetais": 100, "carnes": 150 };
How could I return the key of the highest value item? Example:
obj.maxKey(); // "carnes"
I tested some functions that deal with arrays, but apparently they do not work with objects in the pattern key: value
, example:
Math.max.apply(null, meuArrayAqui);
So, how I could return the key of the highest value item?
Accepts the use of frameworks?
– Fernando Leal
@Fernando jQuery yes, but not third-party plugins.
– Kazzkiq
uhm! I was thinking in that, but now that I realize that in your case is not an array but an object, and this only works for array? Or it can be with array?
– Fernando Leal