Barry Hamilton
Barry Hamilton

Reputation: 973

JavaScript pass array as individual arguments to function

I have the following problem where I have function with parameters and I have an array of the values associated with the parameters.

var myFunction = function(argument_0, argument_1 ) {
//do stuff
}
var arguments = new Array();
arguments[0] = "value0";
arguments[1] = "value1";

How would I go about passing that array in the same format to the function?

Upvotes: 1

Views: 1591

Answers (1)

Jason P
Jason P

Reputation: 27012

You can use .apply()

myFunction.apply(null, arguments);

Upvotes: 7

Related Questions