anson920520 anson920520 - 6 months ago 10
jQuery Question

JQuery ; Declare duplicate global values in

if i have something like these

var executed = false;
var executed2 = false;
var executed3 = false;


How should i put this in a for loop?

Answer

You could make executed a single array rather than a series of variables.

In that case, you could write:

var executed = [];
for(var i = 0; i < 3; i++) {
  executed.push(false);
}

Then, to access the values, you can use:

executed[0] === false // ==> true
executed[1] === false // ==> true
executed[2] === false // ==> true