Is it possible to call a JavaScript function using an array of values as arguments ?
- by Moshe Levine
I'm looking for another way of doing the following:
function call_any_function(func, parameters){
// func => any given function
if(parameters.length==0){ func(); }
if(parameters.length==1){ func(parameters[0]); }
if(parameters.length==2){ func(parameters[0], parameters[1]); }
if(parameters.length==3){ func(parameters[0], parameters[1], parameters[2]); }
if(parameters.length==4){ func(parameters[0], parameters[1], parameters[2], parameters[3]); }
// ... and so on
};
It seems basic but I couldn't find an answer.
Any ideas?