Enumerating an Object's Properties
The for...in loop performs the statement for each property.
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<body>
<script type="text/javascript">
var myData = {
name : "JavaScript",
weather : "Good",
printMessages : function() {
document.writeln("Hello " + this.name + ". ");
document.writeln(this.name +" is " + this.weather + ".");
}
};
myData.printMessages();
for ( var prop in myData) {
document.writeln("Name: " + prop + " Value: " + myData[prop]);
}
</script>
</body>
</html>