你好,我有一个嵌套对象,看起来像这样:
var dogTypes = {
GermanShepard {color: "black and white"},
Beagle {color: "brown and white"},
cheuwahwah {color: "green and white"},
poodle: {color: "purple and white"},
}
我想循环遍历一个嵌套对象中的所有属性,我知道如何处理常规对象,但不知道如何处理嵌套对象。如果有人能帮助我,那就太好了。
for (var key in dogTypes) {
console.log(key + " : " + dogTypes[key])
}
这是我的代码,它会打印输出:
GreatDane : [object Object]
GermanSheppard : [object Object]
Beagle : [object Object]
BullDog : [object Object]
请问在for循环中该如何使用color属性呢?帮忙解答一下,谢谢!