title: JavaScript - Generating combinations from n arrays with m elements
body: <p>I'm having trouble coming up with code to generate combinations from n number of arrays with m number of elements in them, in JavaScript. I've seen similar questions about this for other languages, but the answers incorporate syntactic or library magic that I'm unsure how to translate.</p>
  
  <p>Consider this data:</p>
  
  <pre><code>[[0,1], [0,1,2,3], [0,1,2]]
  </code></pre>
  
  <p>3 arrays, with a different number of elements in them. What I want to do is get all combinations by combining an item from each array.</p>
  
  <p>For example:</p>
  
  <pre><code>0,0,0 // item 0 from array 0, item 0 from array 1, item 0 from array 2
  0,0,1
  0,0,2
  0,1,0
  0,1,1
  0,1,2
  0,2,0
  0,2,1
  0,2,2
  </code></pre>
  
  <p>And so on.</p>
  
  <p>If the number of arrays were fixed, it would be easy to make a hard coded implementation. But the number of arrays may vary:</p>
  
  <pre><code>[[0,1], [0,1]]
  [[0,1,3,4], [0,1], [0], [0,1]]
  </code></pre>
  
  <p>Any help would be much appreciated.</p>