我的问题是:
使用:
console.log(variable[apple]);
variable: {
apple : "xxx"
}
不工作:
console.log(variable.element[apple]);
variable: {
element: {
apple: "xxx"
}
}
element
未定义。
有什么想法吗?
答案 0 :(得分:0)
variable: { //this is a code block labeled "variable"
element: { //this is a code block labeled "element"
apple: "xxx" //this is an expression "xxx" labeled as "apple"
}
}
但是你的代码中没有变量。阅读labeled statements
你可能意味着
var variable = { //now this is a variable containing an object
element: { //and these are properties of that object
apple: "xxx"
}
}
console.log(variable.element.apple);