My problem is:
Works:
console.log(variable[apple]);
variable: {
apple : "xxx"
}
Not working:
console.log(variable.element[apple]);
variable: {
element: {
apple: "xxx"
}
}
element
is not undefined.
Any idea?
My problem is:
Works:
console.log(variable[apple]);
variable: {
apple : "xxx"
}
Not working:
console.log(variable.element[apple]);
variable: {
element: {
apple: "xxx"
}
}
element
is not undefined.
Any idea?
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"
}
}
But there's no variable in your code. Read up about labeled statements
You probably mean
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);