Suppose I have this javascript object:
var obj = {
key_1: {
arr: [
999,
{
key_3: 5
}
]
},
key_2: 'value_2'
};
and I want to access the value 5.
What I would do is obj.key_1.arr[1].key_3.
But I want to have something like a json selector: ['key_1']['arr'][1]['key_3'] and dynamically apply it to the obj.
But I have no clue how to efficiently hold in a variable such a selector.
Also, I would like to have the ability to "concat" such selectors. For example:
// pseudocode
s1 = ['key_1']['arr'];
s2 = [1]['key_3'];
s = s1 + s2;
v = obj[s];
// v === 5
Is there a nice way to do something like this in javascript ?