I have an object like:
var theObject = { keyName1: { keyName2: value2, keyName3: value3, keyName4: value40 }, ..., keyName10: { keyName2: value6, keyName3: value7, keyName4: value8 } } I know I can reference value7 by theObject["keyName10"]["keyName3"] or theObject.keyName10.keyName3 but what I need is to set a variable to something like the search path and somehow pass it to theObject and get value7 directly.
Something like:
var path = keyName10.keyName3; var myValue = theObject(path); Objects can be even further into the object inception. Right now I'm solving it by horrible looking nestled for-loops. Is there a better way I missed?
jsontag because your question has nothing to do with JSON. It's about how to access JavaScript objects. And no, they are not the same: benalman.com/news/2010/03/theres-no-such-thing-as-a-json.