How can I access a dictionary value using a for loop and an array?
For example: I have a dictionary:
var dict = {
machine_41: {
temp: "14",
humidity: "89",
time: Wed Oct 31 2018 12: 27: 16 GMT - 0500(Central Daylight Time)
},
machine_42: {
temp: "20",
humidity: "13",
time: Wed Oct 31 2018 12: 27: 41 GMT - 0500(Central Daylight Time)
},
machine_43: {
temp: "34",
humidity: "36",
time: Wed Oct 31 2018 1 GMT - 0500(Central Daylight Time)
}
I know I can access values by using console.log(dict.machine_41.temp)
However, how can I do this with a for loop, and an array?
I have tried:
let activeMachines = [41,43,45];
for(let i = 0; i < activeMachines.length; i++){
let machine = ('machine_'+ activeMachines[i]);
console.log(htmldata.machine.temp);
}
I was hoping it would substitute machine for machine_41, and so on.