javascript - How to get the highest key and value from object -
I am trying to get the highest key and value from an object, how can I return the desired result ?
Here my object is:
categories = {'personal': 4, 'swag': 3, 'mingle': 2, 'meditation': 1};
desired functionality:
returnMax (categories) // {personal: 4}
Here's how I do it:
categories = {'personal': 4, 'swag': 3, Mingal ': 2,' Meditation ': 1}; Console.log (MaxCat (categories)); Function MaxCat (obj) {var highest = 0; Var arr = []; (Different types of OBJ) (if (obj.hasOwnProperty (prop)) {if (obj [prop]> supreme) {arr = []; highest = obz [prop]; arr [prop] = highest;} }} Return arr;}
Comments
Post a Comment