-1

How do i print the values of the properties of this object. At the moment it just prints the property names not the values.

                     var nyc = {
                     fullName: "New York City",
                     mayor: "Michael Bloomberg",
                     population: 8000000,
                     boroughs: 5
                     };


                    for(var x in nyc) { console.log(nyc[x]); }
6
  • Just do a console.log(nyc)? Commented Jul 14, 2013 at 14:25
  • 4
    That code does print the values. Commented Jul 14, 2013 at 14:26
  • Your code appears to be working when I test it. Commented Jul 14, 2013 at 14:27
  • 2
    It looks like you posted a couple of nearly-identical questions earlier today: the first one asks how to print all of the properties in an object, and the second one also asks how to print all of the properties in an object. The answers to these two questions should give you the information that you need. Commented Jul 14, 2013 at 14:35
  • 2
    Would you please stop posting the same question over and over? Commented Jul 14, 2013 at 14:36

1 Answer 1

3

You should be able to say:

console.log(x + ": " + nyc[x]);

to print both the names and values.

Demo fiddle here.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.