I have a function example(arg1,arg2,arg3,arg4)
and the function uses arg4 for something. Is there a way for me to skip the other arguments instead of having them as unused variables.
I tried example(,,,arg4)
but it does not work
I have a function example(arg1,arg2,arg3,arg4)
and the function uses arg4 for something. Is there a way for me to skip the other arguments instead of having them as unused variables.
I tried example(,,,arg4)
but it does not work
2
Answers
If you’re looking for a compact way to insert a bunch of
null
values into your function arguments, maybe this would work for you.Create a helper function which generates an array of null values.
Then when you call your function, just spread the result of this helper into your arguments.
i.e.
If you have control over the construction of this function you’re using, there are better ways to accomplish a task like this, but as a direct answer to the question you asked, hopefully this helps 🙂 If you’d like any explanation / clarification, please ask.
You could create a wrapper function that takes an object instead of four arguments, and translates that to a call of the original function. Then you can target the arguments you wish to provide by name: