My goal is this:
Say if I have a reference
a: {
b: {
c:{
d: {
//Some properties here.
}
}
}
}
Then by using a string like "a.b.c.d"
(which is not known in advance), I want to be able to transverse the object and get the value of d
(or return null
/ throw Error
).
I am aware that we can always get the value for one depth below (for example a["b"]
and so on) and then this can definitely be achieved using the.split()
and then use loops or recursion, but I was hoping there was a simpler, one step method of doing so.