Given an object, say like this:
const data = {
"menu":{
"id":"file",
"value":"File",
"popup":{
"menuitem":[
{
"value":"New",
"onclick":"CreateNewDoc()"
},
{
"value":"Open",
"onclick":"OpenDoc()"
}
]
}
}
}
I want to get one of the nested properties of the object, say popup, but that could be the name of any type of Web widget - that's a variable. It seems like either one of these two methods would work, but they both return errors:
let propName = "popup";
console.log(data.menu.propName.menuitem);
console.log(data.menu. + propName + .menuitem);
How do you get the property of an object when one of the property names is a variable?