Consider I've an object myObj
And I've a string representing the path to some property inside it: foo.bar
What is the best way to get it from my object?
If I knew the string ahead I would do myObj.foo && myObj.foo.bar
to get it safely
A simple solution would be to split the string 'foo.bar'.split('.')
and than loop over it.
But i'm sure there is a better way
It's a duplicate of other question. they provided a great solution:
given a path
and an obj
get the property value this way
path.split('.').reduce((o, i) => o[i], obj)