Array of functions in JavaScript Last Updated : 26 Dec, 2022 Summarize Comments Improve Suggest changes Share 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 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)); // output: 15Function Syntax 5 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 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 Like