How to pass an array as a function parameter in JavaScript? Last Updated : 06 Dec, 2024 Comments Improve Suggest changes Like Article Like Report Here are different ways to pass an array as a function paramter in JavaScript.1. Using apply() MethodThe apply() method invokes a function with a specified `this` value and an array of arguments. It takes two parameters: the first is the `this` context for the function, and the second is an array of arguments. This allows calling the function with those arguments. JavaScript function unmodifiableFunction(a, b, c) { console.log(`First value is: ${a} Second value is: ${b} Third value is: ${c}`) } arrayToPass = [1, "Two", 3]; unmodifiableFunction.apply(null, arrayToPass); OutputFirst value is: 1 Second value is: Two Third value is: 3 2. Using Spread OperatorThe spread operator is used in places where zero or more arguments are expected. It can be used with iterators that expand in a place where there may not be a fixed number of expected arguments (like function parameters). The required function is called as given the arguments array using the spread syntax so that it would fill in the arguments of the function from the array. JavaScript function unmodifiableFunction(a, b, c) { console.log(`First value is: ${a} Second value is: ${b} Third value is: ${c}`) } arrayToPass = [1, "Two", 3]; unmodifiableFunction(...arrayToPass); OutputFirst value is: 1 Second value is: Two Third value is: 3 3. Using call() MethodThe call() method calls a function with a given this value and arguments provided individually. This method allows you to explicitly specify the this context and the arguments separately. To pass an array as arguments, you can use the spread syntax to expand the array elements as individual arguments. JavaScript function unmodifiableFunction(a, b, c) { console.log(`First value is: ${a} Second value is: ${b} Third value is: ${c}`); } let arrayToPass = [1, "Two", 3]; unmodifiableFunction.call(null, ...arrayToPass); OutputFirst value is: 1 Second value is: Two Third value is: 3 Comment More infoAdvertise with us Next Article How to pass an array as a function parameter in JavaScript? S sayantanm19 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads Passing a function as a parameter in JavaScript In this article, we will pass a function as a parameter in JavaScript. Passing a function as an argument to the function is quite similar to passing a variable as an argument to the function. So variables can be returned from a function. The below examples describe passing a function as a parameter 1 min read JavaScript Passing parameters to a callback function Callback FunctionPassing a function to another function or passing a function inside another function is known as a Callback Function. In other words, a callback is an already-defined function that is passed as an argument to the other code Syntax:function geekOne(z) { alert(z); }function geekTwo(a, 2 min read How to Pass Object as Parameter in JavaScript ? We'll see how to Pass an object as a Parameter in JavaScript. We can pass objects as parameters to functions just like we do with any other data type. passing objects as parameters to functions allows us to manipulate their properties within the function. These are the following approaches: Table of 3 min read How to Store an Object sent by a Function in JavaScript ? When a function in JavaScript returns an object, there are several ways to store this returned object for later use. These objects can be stored in variables, array elements, or properties of other objects. Essentially, any data structure capable of holding values can store the returned object. Tabl 2 min read How to clone an array in JavaScript ? In JavaScript, cloning an array means creating a new array with the same elements as the original array without modifying the original array.Here are some common use cases for cloning an array:Table of ContentUsing the Array.slice() MethodUsing the spread OperatorUsing the Array.from() MethodUsing t 6 min read Like