title: Get input field values and put them into a 2D array
body: <p>I'm trying to get input field values and put them into a two dimensional array. But the problem is am not able to put the values into their desired location.  for instance get n number of values entered, and then put them into nXn array.</p>
  
  <p>Here's the html inputs fields</p>
  
  <pre><code> &lt;table&gt;
     &lt;tr&gt;
       &lt;td&gt;&lt;input type="number" id="0" name="R0C0" placeholder="R0C0" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number"  id="1" name="R0C1" placeholder="R0C1" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number"  id="2" name="R0C2" placeholder="R0C2" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number"  id="3" name="R0C3" placeholder="R0C3" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number"  id="4" name="R0C4" placeholder="R0C4" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number"   id="5"name="R0C5" placeholder="R0C5" &gt;&lt;/td&gt;
     &lt;/tr&gt;
  
     &lt;tr&gt;
       &lt;td&gt;&lt;input type="number" id="6" name="R1C0" placeholder="R1C0" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="7" name="R1C1" placeholder="R1C1" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="8" name="R1C2" placeholder="R1C2" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="9" name="R1C3" placeholder="R1C3" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="10" name="R1C4" placeholder="R1C4" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="11" name="R1C5" placeholder="R1C5" &gt;&lt;/td&gt;
     &lt;/tr&gt;
  
     &lt;tr&gt;
       &lt;td&gt;&lt;input type="number" id="12" name="R2C0" placeholder="R2C0" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="13" name="R2C1" placeholder="R2C1" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="14" name="R2C2" placeholder="R2C2" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="15" name="R2C3" placeholder="R2C3" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="16" name="R2C4" placeholder="R2C4" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="17" name="R2C5" placeholder="R2C5" &gt;&lt;/td&gt;
     &lt;/tr&gt;
  
     &lt;tr&gt;
       &lt;td&gt;&lt;input type="number" id="18" name="R3C0" placeholder="R3C0" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="19" name="R3C1" placeholder="R3C1" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="20" name="R3C2" placeholder="R3C2" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="21" name="R3C3" placeholder="R3C3" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number"id="22"  name="R3C4" placeholder="R3C4" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="23" name="R3C5" placeholder="R3C5" &gt;&lt;/td&gt;
     &lt;/tr&gt;
  
     &lt;tr&gt;
       &lt;td&gt;&lt;input type="number" id="24" name="R4C0" placeholder="R4C0" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="25" name="R4C1" placeholder="R4C1" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="26" name="R4C2" placeholder="R4C2" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="27"name="R4C3" placeholder="R4C3" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="28" name="R4C4" placeholder="R4C4" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="29" name="R4C5" placeholder="R4C5" &gt;&lt;/td&gt;
     &lt;/tr&gt;
  
     &lt;tr&gt;
       &lt;td&gt;&lt;input type="number" id="30" name="R5C0" placeholder="R5C0" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="31" name="R5C1" placeholder="R5C1" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="32" name="R5C2" placeholder="R5C2" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="33" name="R5C3" placeholder="R5C3" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="34" name="R5C4" placeholder="R5C4" &gt;&lt;/td&gt;
       &lt;td&gt;&lt;input type="number" id="35" name="R5C5" placeholder="R5C5" &gt;&lt;/td&gt;
     &lt;/tr&gt;
   &lt;/table&gt;
  &lt;button onClick="checking()"&gt;check&lt;/button&gt;
  </code></pre>
  
  <p>....with four more rows and ids in increasing order till 36.</p>
  
  <p>javascript code:</p>
  
  <pre><code>const checking = () =&gt;{
     //create a 2D array of 6 rows and 6 columns
    var x = new Array(6);
    for (var i = 0; i &lt; x.length; i++) {
      x[i] = new Array(6);
    }
  
      //loop to get all input values ie from id=1 to id=36
      var k=0;
      for(k; k&lt;35; k++){
        //loop for rows
        for(var i=0; i&lt;x.length; i++){
          var xValues = x[i]; //x[i] reference the array object
          //loop for columns
           for(var j=0; j &lt; xValues.length; j++){
            //put the input values to the 2D array respective position
             x[i][j] =document.getElementById(k).value;
            //console.log("x"+"["+i+"]"+"["+j+"]"+" = "+x[j]);
           }
        }
     }
   }//end function
  </code></pre>
  
  <p>for supposed an input say,</p>
  
  <pre><code>x = [
    [1,2,3,4,5,6],
    [2,3,4,5,5,6],
    [1,2,3,4,5,6],
    [3,5,4,2,2,2],
    [4,5,3,4,3,2],
    [4,3,2,3,5,3]
  ];
  </code></pre>
  
  <p>I expect an output of,</p>
  
  <pre><code>1,2,3,4,5,6
  2,3,4,5,5,6
  1,2,3,4,5,6
  3,5,4,2,2,2
  4,5,3,4,3,2
  4,3,2,3,5,3
  </code></pre>
  
  <p>However, from my script above, I get wired results.
  something like this............</p>
  
  <pre><code>x[0][0] = 1,,,,, 
  x[0][1] = ,,,,, 
  x[0][2] = ,,,,, 
  x[0][3] = ,,,,, 
  x[0][4] = ,,,,, 
  x[0][5] = ,,,,, 
  x[1][0] = 1,1,1,1,1,1 
  x[1][1] = 1,1,,,, 
  x[1][2] = ,,,,, 
  x[1][3] = ,,,,, 
  x[1][4] = ,,,,, 
  x[1][5] = ,,,,, 
  x[2][0] = 1,1,1,1,1,1 
  x[2][1] = 1,1,1,1,1,1
  x[2][2] = 1,1,1,,, 
  x[2][3] = ,,,,, 
  x[2][4] = ,,,,, 
  x[2][5] = ,,,,, 
  x[3][0] = 1,1,1,1,1,1 
  x[3][1] = 1,1,1,1,1,1 
  x[3][2] = 1,1,1,1,1,1 
  x[3][3] = 1,1,1,1,,
  x[3][4] = ,,,,,
  ....................
  </code></pre>