Have a situation where I'm being provided a path from an external source, and I need to pull that key out of an object and return the value.
The document schema is also unknown at design time, so this has to be fully flexible.
eval() does what I want, but I'm doing my due diligence to see if there's another way.
var obj = {"a": {"b": {"c": 42}, "d": [8,9]}}
var path = 'a.b.c';
eval('obj.' + path);
42
Anyone know a way, without 'eval', that I can use the string 'a.b.c' to find that nested value in obj?
This must support indexes into lists as well:
var path = 'a.d[1]';
eval('obj.' + path);
9
I can use jQuery if it offers a viable solution, I just don't see anything evident.
Thanks!