When you do for..in , you iterate over the keys, not the values.
In for (var person in people) , person is a string; each of the keys: "john" and "bob" .
In your second loop, you iterate over all the properties of this string, which prints the βindexesβ in the string (you can refer to strings like arrays string[1] ).
You need to get the value of the object before you can iterate over it:
for (var person in people) { var thisPerson = people[person]; for (var property in thisPerson) { console.log(property); } }
source share