title: How to insert elements into specific index in a 2D array in javascript?
body: <p>I have an object that looks like below</p>
  <pre><code>const tableData = [
      {
          
          &quot;Location&quot;: &quot;London&quot;,
          &quot;Status&quot;: &quot;Unknown&quot;
      },
      {
          
          &quot;Location&quot;: &quot;Delhi&quot;,
          &quot;Status&quot;: &quot;Reachable&quot;
      },
      {
          
          &quot;Location&quot;: &quot;Berlin&quot;,
          &quot;Status&quot;: &quot;Unknown&quot;
      },
      {
          
          &quot;Location&quot;: &quot;Tokyo&quot;,
          &quot;Status&quot;: &quot;Busy&quot;
      },
  ]
  </code></pre>
  <p>Now I want to create a 2D array which will hold this information in a certain way. Here is my code below</p>
  <pre><code>const statusOrder = {&quot;Reachable&quot;: 0, &quot;Busy&quot;: 1, &quot;Unknown&quot;: 2}
  let statusOrderInfo = Array(Object.keys(statusOrder).length).fill([]);
  for(let i=0; i&lt; tableData.length; i++) {
      const status = tableData[i][&quot;Status&quot;].trim()
      const statusIndex = statusOrder[status]
      statusOrderInfo[statusIndex].push(tableData[i])
  }
  console.log(statusOrderInfo)
  </code></pre>
  <p>As you can see I want each item of the <code>tableData</code> object to be in a certain index of the 2D array. So the item that contains <code>Status</code> as <code>Reachable</code> should be at index 0, the item that contains the <code>Status</code> as <code>Busy</code> should be at index 1 and so on.</p>
  <p>So the final output should look like</p>
  <pre><code>[
     [
        {
           &quot;Location&quot;:&quot;Delhi&quot;,
           &quot;Status&quot;:&quot;Reachable&quot;
        }
     ],
     [
        {
           &quot;Location&quot;:&quot;Tokyo&quot;,
           &quot;Status&quot;:&quot;Busy&quot;
        }
     ],
     [
        {
           &quot;Location&quot;:&quot;London&quot;,
           &quot;Status&quot;:&quot;Unknown&quot;
        },
        {
           &quot;Location&quot;:&quot;Berlin&quot;,
           &quot;Status&quot;:&quot;Unknown&quot;
        }
     ]
  ]
  </code></pre>
  <p>But I get a wrong output on running the above code even though I am targeting the correct index. What's wrong in my approach?</p>