Say I have a config file in which I have paths to JSON properties. My JSON looks like:
var test = { test: { test2: { test3: 1 } } }
and I have a string str = "test.test2.test3"
I know I can access the top level one like this: var foo = "test", test[foo]
But test["test.test2.test3"] does not work. On the other hand test["test"]["test2"]["test3"] works, but this is not a one liner if I have more complex objects (some can be 5 levels in, some can be 3 etc)
Is there any way to access this property directly instead of splitting on the dot and looping through?
Did anyone’s head explode?
It’s either that or
Take your pick from the bad practice basket.
Though for the first example if you actually want the value you’d want to do this
But that kind of takes away from the purity of this bad practice masterpiece.