EN
JavaScript - array of functions
0 points
In this article, we would like to show you how to declare and use an array of functions in JavaScript.
In this example, we create three functions, declare an array of functions and call them using array notation with given indexes.
xxxxxxxxxx
1
function function1(text) {
2
console.log(text + ' - 1');
3
}
4
5
function function2(text) {
6
console.log(text + ' - 2');
7
}
8
9
function function3(text) {
10
console.log(text + ' - 3');
11
}
12
13
var array = [function1, function2, function3];
14
15
array[0]('example text'); // example text - 1
16
array[1]('example text'); // example text - 2
17
array[2]('example text'); // example text - 3