In Ruby, you can use the splat (*
) operator to capture a variable number of arguments to a function, or to send the contents of an array to a function as an argument, like so:
def example(arg1, *more_args)
puts "Argument 1: #{arg1.inspect}"
puts "Other arguments: #{more_args.inspect}"
end
test_args = [1, 2, 3]
example(*test_args)
Output:
Argument 1: 1
Other arguments: [2, 3]
What's the equivalent of this in JavaScript?