Let's say I have the following object:
var a = {
x: {
y: 'Good job!'
}
z: 'Nice try...'
}
and the following strings:
var key1 = "z";
var key2 = "x.y";
Is there a way to access the value of y
by using the key2
variable?
console.log(a[key1])
will work because it will get evaled to a['z']
, but a[key2]
won't because it will get evaled to a['x.y']
which is not valid.