Array of functions in JavaScript Last Updated : 26 Dec, 2022 Comments Improve Suggest changes Like Article Like Report Given an array containing functions and the task is to access its element in different ways using JavaScript. Approach: Declare an array of functions.The array of functions works with indexes like an array function. Example 1: In this example, the function call is initiated from the element of the array but the function is defined somewhere else. We can pass arguments to the function while calling. html <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <h3>Array of functions in javascript</h3> <p id="GFG_UP" style="font-size: 19px; font-weight: bold;"> </p> <button onClick="GFG_Fun()"> click here </button> <p id="GFG_DOWN" style="color: green; font-size: 24px; font-weight: bold;"> </p> <script> var up = document.getElementById('GFG_UP'); var down = document.getElementById('GFG_DOWN'); function firstFun(str) { down.innerHTML = str; } function secondFun(str) { down.innerHTML = str; } function thirdFun(str) { down.innerHTML = str; } // Declare array of functions var arrayOfFunction = [ firstFun, secondFun, thirdFun ] up.innerHTML = "Calling function from the array of functions"; // Function call function GFG_Fun() { arrayOfFunction[0]("This is first function"); } </script> </body> Output: Example 2: In this example, the function (anonymous) itself is defined as the elements of the array. We can access it by accessing the element of the array followed by (). html <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <h3>Array of functions in JavaScript</h3> <p id="GFG_UP" style="font-size: 19px; font-weight: bold;"> </p> <button onClick="GFG_Fun()"> click here </button> <p id="GFG_DOWN" style="color: green; font-size: 24px; font-weight: bold;"> </p> <script> var up = document.getElementById('GFG_UP'); var down = document.getElementById('GFG_DOWN'); // Declare an array of functions var arrayOfFunction = [ function() { down.innerHTML = "Inside First function"; }, function() { down.innerHTML = "Inside Second function"; }, function() { down.innerHTML = "Inside Third function"; } ] up.innerHTML = "Calling function from the array of functions"; function GFG_Fun() { arrayOfFunction[2](); } </script> </body> Output: Comment More infoAdvertise with us Next Article Array of functions in JavaScript P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies javascript-functions Similar Reads Arrow functions in JavaScript An arrow function is a shorter syntax for writing functions in JavaScript. Introduced in ES6, arrow functions allow for a more concise and readable code, especially in cases of small functions. Unlike regular functions, arrow functions don't have their own this, but instead, inherit it from the surr 5 min read JavaScript Array join() Function The JavaScript Array.join() method is used to join the elements of the array together into a string. The elements of the string will be separated by a specified separator and its default value is a comma(, ). Syntax: Array.join([separator]) Parameters: [separator]: A string to separate each element 2 min read Functions in JavaScript Functions in JavaScript are reusable blocks of code designed to perform specific tasks. They allow you to organize, reuse, and modularize code. It can take inputs, perform actions, and return outputs.JavaScriptfunction sum(x, y) { return x + y; } console.log(sum(6, 9));Output15 Function Syntax and W 5 min read Are functions objects in javascript? Yes, Functions are considered first-class objects, which means they have the same capabilities as other objects. The following are examples that demonstrates functions behaving as objects:Can be assigned to variableJavaScript// Assign a function to a variable const x = function() { return `GfG!`; }; 1 min read JavaScript Array find() function JavaScript arr.find() function is used to find the first element from the array that satisfies the condition implemented by a function. If more than one element satisfies the condition then the first element satisfying the condition is returned. Syntax: arr.find(function(element, index, array), this 3 min read JavaScript Apply() Function The apply() method is used to write methods, which can be used on different objects. It is different from the function call() because it takes arguments as an array. Syntax: apply() Return Value: It returns the method values of a given function. Example 1: This example illustrates the apply() functi 1 min read Most useful JavaScript Array Functions â Part 1 In this article, we are going to discuss the following two JavaScript array functions. Both of these functions are widely used in industry and make the JavaScript code clean, modularized, and easy to understand. Array.prototype.every()Array.prototype.some()Array.prototype.every(): This function is u 6 min read How to write a function in JavaScript ? JavaScript functions serve as reusable blocks of code that can be called from anywhere within your application. They eliminate the need to repeat the same code, promoting code reusability and modularity. By breaking down a large program into smaller, manageable functions, programmers can enhance cod 4 min read Types of Arrays in JavaScript A JavaScript array is a collection of multiple values at different memory blocks but with the same name. The values stored in an array can be accessed by specifying the indexes inside the square brackets starting from 0 and going to the array length - 1([0]...[n-1]). A JavaScript array can be classi 3 min read JavaScript Array findIndex() Function JavaScript arr.findIndex() function is used to find the index of the first element that satisfies the condition checked by the argument function from the given array. Suppose you want to find the index of the first element of the array that is even. Syntax: array.findIndex(function(element, index, a 3 min read Like