title: Struggling to understand how this multi-layer for loop works
body: <p><strong>Question</strong></p>
  
  <p>The following function is supposed to create a two-dimensional array with m rows and n columns of zeroes. </p>
  
  <p><strong>Answer</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function zeroArray(m, n) {
    // Creates a 2-D array with m rows and n columns of zeroes
    let newArray = [];
    let row = [];
    for (let i = 0; i &lt; m; i++) {
      // Adds the m-th row into newArray
  
      for (let j = 0; j &lt; n; j++) {
        // Pushes n zeroes into the current row to create the columns
        row.push(0);
      }
      // Pushes the current row, which now has n zeroes in it, to the array
      newArray.push(row);
    }
    return newArray;
  }
  
  let matrix = zeroArray(3, 2);
  console.log(matrix);</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>My Question</strong></p>
  
  <p>I am familiar with having a for loop inside of a for loop, to iterate through a second layer of an array. But in this example it seems particularly confusing. </p>
  
  <p>Please could you explain step by step what is happening here. </p>