Array of Functions in Javascript

Arrays of functions need to be called with parentheses. 

var array_of_functions = [
    first_function,
    second_function,
    third_function,
    forth_function
]

array_of_functions[0]();

If each of the functions should be called with parameters, the parameter should be passed along while invoking the function. 

var array_of_functions = [
    first_function,
    second_function,
    third_function,
    forth_function
]

array_of_functions[0]('string');

References

Array of functions



 







Comments