Consider the following JSON object:
{
"data": {
"data2": {
"myProp": "hello"
}
}
}
I need to be able to dynamically access the deep property myProp
, but the catch is, that I need to be able to write the deep property as a regular string. i.e:
let sortByThisValue = 'data.data2.myProp'
So I already started:
let propertyArray = sortByThisValue.split('.')
//Do something here
let myVal = data.[data2][myProp] //Or data.data2.myProp