Say I have a Javascript array which contains numbers between 0 and 5. Each of the numbers is really an instruction to call a specific function. For example:
var array = [lots of data];
for(i=0; i<array.length; i++){
if(i == 0){ function0(); };
if(i == 1){ function1(); };
if(i == 2){ function2(); };
if(i == 3){ function3(); };
if(i == 4){ function4(); };
if(i == 5){ function5(); };
}
This seems like an awful lot of branching and unnecessary checks. What would be a more performance minded way to call the function?
I've thought about dynamically creating the function names using eval, but isn't there a better way?