I have a function
await mainFunction(function1, function2, function3)
I also want to pass multiple functions into the mainFunction
const mainFunction = async (function1, function2, function3) => async ({ param1, param2, param3}) => {
const params = { param1, param3, param3};
How do I do this without passing it as another param?
3
Answers
If I understand you right, you want to pass indefinite number of arguments to your main function, so you can use the
...rest
parameter.Note. You can call the
rest parameter
whatever you want.So in your code it will look something like this:
You can read more about it here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters
You can try using
Rest parameters (...)
that allows to pass any number of functions as an array:if you want to maintain your current syntax you can do it like this