Underscore is a popular Javascript library that provides a number of utility functions for working with arrays, objects, functions, etc. One such function is restarguments
.
The restarguments
function is used to extract the remaining arguments of a function call as an array. It is particularly useful when you want to define a function with a variable number of arguments. Here's an example:
index.tsx193 chars7 lines
In the example above, we define a function myFunc
with two arguments firstArg
and secondArg
. We then call the function with four arguments, including two that we do not anticipate. We use _.restarguments
to extract the remaining arguments (["baz", "qux"]
) and log them to the console.
Note that _.restarguments
returns an array, so you can perform array operations on it as necessary.
gistlibby LogSnag