How can I pass dynamic arguments to a function, e.g
var customvar = 1; //example
function iLike(){
console.log("you like ... (I know how to receive the arguments!)")
}
function getDrink(){
return (customvar == 1 ? ('pepsi','cola') : ('drpepper'));
}
iLike('peanuts', 'pizza', getDrink());
iLike('peanuts', 'pizza', 'pepsi', 'cola'); // = result
How to pass arguments from getDrink() correctly – I do only do receive ‘cola’ but not ‘pepsi’.
If you want
getDrinkto return an array containing'pepsi'and'cola'then the syntax is['pepsi', 'cola']I’m not quite sure if that’s what you wanted…
Note that that would still give you:
Three arguments, out of which the last is an array, rather than four arguments.
If you want
iLiketo be called with four string arguments, you might want to call it like this: