-4

I have an Array of Arrays and a method that expects N arguments of type Array.

For example, if I have: let arr = [[0, 1], [2, 3], [4, 5]];

arr has 3 arrays inside, so I could do this:

theFunction(arr[0]);
theFunction(arr[0], arr[1]);
theFunction(arr[0], arr[1], arr[2]);

The question is: How can I accomplish this if I don't know the number of arrays?

kosmosan
  • 373
  • 3
  • 12

1 Answers1

0
   theFunction(...arr)

Just spread the array into the function arguments.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151