I always come across situations in programming where I want to have a bunch of variables defined in a loop (e.g., soldierA, soldierB, soldierC,…) and assign them to certain objects.
someClassA = Ext.extend(someClassB) {
initComponent {
this.weekdays = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
'Friday', 'Saturday','Sunday'
];
for(var i = 0; i<7; i++) {
var dummy = "this.vacation" +this.weekdays[i];
dummy = 1;
};
console.log("I desire the following to be a 1: " +this.vacationMonday);
}
}
Console lists an undefined elements.
What is the recommended course of action?
You have to use the bracket notation to set dynamic variable names. Also note you have to assign directly, not the way you have it listed.