Access Object Name and convert it to String separated by comma - Javascript Object

Javascript examples for Object:Object Property

Description

Access Object Name and convert it to String separated by comma

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  a  v  a2s .  c om*/
var p = new Object();
p.data = new Object();
p.data.address = "Main street";
p.data.header = "test header";
p.data.phoneFax = "fax";

for(var key in p.data){
   if(!p.data.hasOwnProperty(key))
      continue;
   if(key==="header")
      continue;
   document.getElementById("text").innerHTML += key + ", ";
}
    }

      </script> 
   </head> 
   <body> 
      <p id="text"></p>  
   </body>
</html>

Related Tutorials