title: Dynamic number of nested loops (in Javascript)
body: <blockquote>
    <p>I want to generate every possible combination of numbers, with <em>n</em> beeing the highest.</p>
  </blockquote>
  
  <p>Eg:</p>
  
  <pre><code>0 0
  0 1
  0 2
  1 0
  1 1
  1 2
  2 0
  2 1
  2 2
  </code></pre>
  
  <hr>
  
  <p>My current approach to this is pretty simple, just <em>n</em> for loops.<br>
  The problem with this is, that I don't know <em>n</em>.</p>
  
  <pre><code>n = 3;
  for (a=0; a &lt;= n; a++) {
      for (b=0; b &lt;= n; b++) {
          for (c=0; c &lt;= n; c++) {
              console.log(`${a} ${b} ${c}`);
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <p>I need a way of generating these loop dynamically.</p>
  
  <p><br><br>
  <em>Any other approach for generating all possibilities is also welcome.</em></p>