I have an array of values:
[\'a\', \'b\', \'c\', \'d\']
and I need to pass these as parameters to a function:
window.myFunction
In ES6 you can use spread syntax.
As from Docs:
Spread syntax allows an iterable such as an array expression or string to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected.
Your syntax will be:
var array = ['a', 'b', 'c', 'd'];
myFunction(...array);
Demo:
var array = ['a', 'b', 'c', 'd'];
myFunction(...array);
function myFunction(p1, p2, p3, p4) {
console.log(p1, p2, p3, p4);
}