There are objects in my possession that contain various nested objects:
let obj = {
nestedObject: {
key: value
}
}
or
let obj2 = {
nestedObject2: {
nestedObject3: {
key2: value2
}
}
}
and so on.
Retrieving the values from these objects is straightforward:
obj.nestedObject.key
obj['nestedObject']['key']
or
obj2.nestedObject2.nestedObject3.key2
obj2['nestedObject2']['nestedObject3']['key2']
However, I need to handle this dynamically for any object structure that comes my way. I receive random objects with the same format and a string indicating where to locate the values. For example, for obj2 in the sample above, I would receive the string:
"nestedObject2.nestedObject3.key2"
How can I utilize this information to retrieve the desired value? The methods used previously no longer apply, and attempts like:
obj2['nestedObject2.nestedObject3.key2']
do not yield the expected results.