Javascript examples for Language Basics:Introduction
You enumerate the properties an object has using the for...in statement.
<!DOCTYPE HTML> <html> <head> <title>Example</title> </head> <body> <script type="text/javascript"> var myData = {//from w w w. j a va 2 s. c o m name: "java2s.com", topic: "CSS", printMessages: function() { document.writeln("Hello " + this.name + ". "); document.writeln("Today is " + this.topic + "."); } }; for (var prop in myData) { document.writeln("Name: " + prop + " Value: " + myData[prop]); } </script> </body> </html>