The question is similar to this: How do I interpolate a variable as a key in a JavaScript object?
However, I have a difficult on using variables on nth keys:
I had a object, which is:
var object = {};
object.foo = "foo";
object.foo.bar = "bar";
object.foo.bar.alice = "alice";
object.foo.bar.alice.bob = "bob";
I am able to get the value (foo
) for object.foo
by using the variable object["foo"]
But I cannot find out a way to access to object.foo.bar
value.
I tried object["foo"]["bar"]
, but it does not work.
In addition to my question, how can I get the value for
object.foo.bar.alice
object.foo.bar.alice.bob
By using variable as well?
Thanks.