javascript function with array parameter 1

javascript function with array parameter

const args = ['test0','test1','test2'];
function call_me(param1, param2, param3){
  //
}
call_me.apply(this, args);

Here is what the above code is Doing:
1. We create an array of arguments.
2. We create a function that takes three parameters.
3. We call the function using the apply() method.
4. The apply() method takes two parameters:
1. The first parameter is the object that will be bound to this.
2. The second parameter is an array of arguments.

The apply() method is very similar to the call() method. The only difference is that the call() method takes an argument list, while the apply() method takes an array of arguments.

Similar Posts