此代码如何读取以读取对象,能够读取其中的对象:
var book = {
"main title": "Javascript",
"sub-title": "Def Guide",
"for": "all audiences",
author: {
firstname: "David",
surname: "Fatagans"
}
};
for (propName in book){
console.log("key: " + propName + " value: " + book[propName]);
if (typeof book[propName] === "object"){
for (innerObject in book[propName]){
console.log("key: " + innerObject + "value: " + book[propName][innerObject])
}
}
}