I have objects which e.g. look like
var myObject =
{
propertyA: 'valueA',
propertyB: 'valueB',
propertyC: {
subProperty1: 'subvalue1',
subProperty2: 'subvalue2'
}
}
In some config variable I retrieve some string, it could look like:
configString1 = 'propertyA';
configString2 = 'propertyC.subProperty2';
It's easy to retrieve the values from my object by the first string as property:
var value = myObject[configString1]; // returns valueA
But how could I achieve the same thing for configString2 as
var value = myObject[configString2]; // not defined
obviously is not working.
Of course I could start to check wether there's a dot in my string, split it and with a couple of if-else statements I can make sure to get the right values.
But is there some easy way to achieve that in a generic way with Javascript/Angular?