Get variable name using "reflection" - Javascript Object

Javascript examples for Object:Reflection

Description

Get variable name using "reflection"

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(){/*ww w .  j  av  a 2 s  .c o m*/
//This is variable you want to get the name
var prop;
var obj = {prop};
for(var propName in obj){
  console.log(propName);
  break;
}
    }

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

Related Tutorials