You can use Function.prototype.apply like this
myFunctionTest.apply(this, arrayOfName);
The apply function passes all the elements of arrayOfName as parameters to myFunctionTest.
As the number of parameters grow in number, you may not want to or find it difficult to maintain the number or parameters. Don't worry, JavaScript has got that covered :) It has something called arguments which is an array like object. You can access the first parameter with arguments[0], like accessing a normal array object.
var arrayOfName = [];
arrayOfName.push("module1");
arrayOfName.push("module2");
arrayOfName.push("module3");
arrayOfName.push("module4");
function myFunctionTest(param1, param2, param3) {
console.log(param1, param2, param3);
console.log(arguments);
}
myFunctionTest.apply(this, arrayOfName);
// module1 module2 module3
// { '0': 'module1', '1': 'module2', '2': 'module3', '3': 'module4' }
If you want to require node modules, with this method
var modules = ["lodash", "underscore", "q"];
require.apply(this, modules);
But if you want to get the objects returned by the require for each of the modules, then your best bet would be using Array.prototype.map with require, like this
console.log(modules.map(require));
If you have a function like this
function modules(module1, module2, ...) {
...
}
And if you want to invoke it with all the loaded modules, then you would do something like this
modules.apply(this, modules.map(require));