I'm trying to loop through an object's values which in turn are objects of there own with data that I want to retrieve. I'm trying to get the data that matches a variable that is created dynamically, not a hard-coded path. The only solutions I can find are for objects that have data attached at the top level not nested in another object. Below is a simple version of my problem. Thank you in advance.
const VMs = {
'VM01': {
"1": "value1",
"2": "value2",
"3": "value3"
},
'VM02': {
"1": "value1",
"2": "value2",
"3": "value3"
},
'VM03': {
"1": "value1",
"2": "value2",
"3": "value3"
}
};
const thisVM = 'VM03'; // Hardcoded here but actually this.$route.params.data (data not defined in this example)
for (let obj in VMs) {
console.log(obj) // this is only a string of the key eg "VM01". I
// want obj to be an object where I can reference its data.
if (obj = thisVM) {
// get data from this VM
}
}