For example, if I have a string:
var foo = 'a.b.c';
... and Object:
var bar = {
a: {
b: {
c: null
}
}
}
How can I use the string to set the value of 'c' to 'Hello World!"?
For example, if I have a string:
var foo = 'a.b.c';
... and Object:
var bar = {
a: {
b: {
c: null
}
}
}
How can I use the string to set the value of 'c' to 'Hello World!"?
Another example with a small function (DEMO):
Also to get the value:
Here's one of those not so simple or consistent ways
FIDDLE
Another possible solution is to use eval, but it is unsafe and mostly discouraged:
FIDDLE