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

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -