Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Joe Consterdine
Joe Consterdine
13,965 Points

Converting Object In To HTML?

Hey guys,

I've learn the JS basics.

I've just started making object constructors and had a few questions.

1.How do you convert them in to HTML?

My idea was to use the information and display each person's properties as text next to a photo.

I know you can do it separately by doing something like:

document.write(dave.age);

but how do you do it for all their properties?

2.When you display an object in the browser it only shows that object on a blank page without the rest of the HTML. Why is that?

3.Are objects meant to be displayed to the browser? If they aren't why is this? And how would you use them effectively?

Thanks Joe

1 Answer

You can loop through the object:

for (var d in dave) {
  if (dave.hasOwnProperty(d)) {
    document.write(d + " : " + dave[d]);
  }
}