I need to call a variable from within a variable.
I have a variable called vmX_cores. I need to loop through the vms I have and call that variable dynamically.
var vms = ["vm1", "vm2", "vm3"];
var totalVms = vms.length;
var vm1_cores = 2;
var vm2_cores = 4;
var vm3_cores = 8;
function ifScript() {
if (totalVms == 0) {
return 'done';
} else {
var curVM = vms[totalVms - 1];
var variableToUse = curVM + '_cores';
totalVms--;
return 'notDone';
}
}
When I call variableToUse this returns "vmX_cores" but I need it to return the number not a string.