嗨,我有一个看起来像这样的嵌套对象
var dogTypes = {
GermanShepard {color: "black and white"},
Beagle {color: "brown and white"},
cheuwahwah {color: "green and white"},
poodle: {color: "purple and white"},
}
Run Code Online (Sandbox Code Playgroud)
我试图遍历嵌套对象中的所有属性,我知道如何使用常规对象而不是嵌套对象来执行此操作,因此如果有人可以帮助我,那就太好了。
for (var key in dogTypes) {
console.log(key + " : " + dogTypes[key])
}
Run Code Online (Sandbox Code Playgroud)
这是我打印出来的代码
GreatDane : [object Object]
GermanSheppard : [object Object]
Beagle : [object Object]
BullDog : [object Object]
Run Code Online (Sandbox Code Playgroud)
我将在哪里将颜色属性合并到 for in 循环中,请帮忙!谢谢