Possible Duplicate:
Accessing nested JavaScript objects with string key
Maybe the title is not clear enough, I just didn't know how to specify what I'm looking for and my English is really bad, sorry.
I'm trying to create function that returns object value, but also plays nice with nested objects. For example:
var obj = {
foo: { bar: 'baz' }
};
I want to access the value of obj.foo.bar by suppling the string "foo.bar" to the function.
function(obj, path) {
// Path can be "foo.bar", or just "foo".
}
Thanks!
var obj = {foo: { bar: 'baz' }};({foo:{bar:value}} = obj);console.log(value);
– Alexander