Is there a way to pass an array as an argument to the Function() constructor in JavaScript?

Viewed 27

So what I have right now is a code that pulls function information from a database (right now, it's just the name of the one sole argument and the function body)

I want to expand this so that it is possible to pass multiple arguments to the function.

However from what I am seeing, there doesn't really seem to be a way to pass an array of argument names to the Function() constructor. Every place I find looks like they pass every argument name individually as a string (and not as an array).

Is there any way to pass the array directly to the constructor?

For a bit more context, let's say this is what I have right now in the JSON:

{
                "arguments": "input",
                "body": "return 0;"
}

And this is what I have in the function:

var f = new Function(json.arguments, json.body);
return f(in);

I would like to turn arguments into an array (say ["in1", "in2", "in3"]) and hopefully keep a single declaration for f.

0 Answers
Related