9

Possible Duplicate:
How do I enumerate the properties of a javascript object?

Good day!

I want to determine all the properties of my navigator using javascript by doing this following code:

<script type="text/javascript">
    for(var property in navigator){ 
        str="navigator."+ property;   //HAVING A PROBLEM HERE...
        document.write(property+ "&nbsp;&nbsp;<em>"+ 
        str+"</em><br />");
    } 
</script>

But the concatenation of my str variable prints as it is. What i need is the actual value of the property.

eg. navigator.appCodeName should print mozilla instead of navigator.appCodeName itself.

Thank you in advance.

Community
  • 1
  • 1
newbie
  • 14,582
  • 31
  • 104
  • 146

1 Answers1

14

You want to use navigator[property] to access the values assigned to the properties.

for(var property in navigator){ 
    var str = navigator[property]
    document.write(property+ "&nbsp;&nbsp;<em>"+str+"</em><br />");
} 

You could also benefit from dropping document.write(), it's rarely the best way to modify the DOM.

alex
  • 479,566
  • 201
  • 878
  • 984