I want to call multiple functions in a JavaScript 'for' loop, but they are only being called the first time and the loops terminates.
I have tried making the functions unique, by passing a value to them, using some generic function caller such as:
for(i=0; i<50; i++){
alert('test');
generator_function(i);
}
function generator_function(variable){
function1(variable);
function2(variable);
function3(variable);
function4(variable);
var sum = local_array.reduce(function(a, b) { return a + b });
var avg = sum / local_array.length;
}
Which seems to work, but the local arrays still hold the elements from the first loop.
Is there a better way of calling a collection of functions inside a loop? I have global arrays which are being altered in these loops and am wondering if they need to be local, i.e. inside the functions somehow?
for(i=0; i<50; i++){hereiis a global variable if inside any one of the function(where i is again in global scope)is value is changed to > 50 then the loop will get terminated. Tryfor( var i=0; i<50; i++){insteadgenerator_function. Have you checked the console, there should be an error message.var: ).