Lets say you have an object you created in javaScript and you want to print out the property and the corresponding value, how would you do that? Here is an example below. Obviously in real life I wouldn't keep making objects, but bear with me here.
var houseA = {
county: "Falls County",
school: "Trinity West Elementary School",
square_feet: 2500,
specs: "3 bedroom and 2 bath"
};
for(var prop in houseA) {
document.write(prop);
}
//This would out put
county
school
square feet
specs
How would you make it output the values with the properties?
I know you can do it mannually by doing below.
document.write(houseA.county);
document.write(houseA.school);
so on and so fourth.
No comments:
Post a Comment