I am attempting to dynamically access an object property from an array of strings that contain the path to the desired value. Currently, it only accesses the first index ('Properties') and returns 'undefined' for the rest. I am expecting the output to be "ES_STUE".
let objPath = ["properties.Constraints.Level"];
const object = {
properties: {
Visibility: {
"Tender Code": "",
},
Data: {
DTU_ClassificationNumber: "",
DTU_InformationAccuracy: "",
},
"Model Properties": {
"Workset (Manual)": "No",
},
Constraints: {
Level: "ES_STUE",
Host: "Level : ES_STUE",
"Offset from Host": "0.000 mm",
"Moves With Nearby Elements": "No",
"Default Elevation": "0.000 mm",
},
},
};
for (const iterator of objPath) {
const keySegment = iterator.split(".");
for (const prop of keySegment) {
console.log(prop);
const result = object[prop];
//const result = object["Properties"]["Constraints"]["level"] not sure if this is correct
console.log(result); // should return "ES_STUE"
}
}