Return name of object property by value - Javascript Object

Javascript examples for Object:Object Property

Description

Return name of object property by value

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from w w w  . j av a  2s  . c o  m*/
var codes = {
    "admin": 3,
    "manager": 2,
    "basic": 1
}
var accountType = 2;
for (i in codes) {
    if (codes[i] == accountType) {
       console.log(i);
    }
    
}
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials