title: create dynamic multidimmensional associative array in javascript from json
body: <p>I get a JSON object from PHP that holds multiple rows like this:</p>
  
  <pre><code>id | type   | amount| age
  1  |  abc   |   1    |  1
  2  |  def   |   2    |  1
  3  |  def   |   4    |  2
  4  |  def   |   13   |  3
  </code></pre>
  
  <p>I run it through JavaScript:</p>
  
  <pre><code>$.ajax({
      type: 'POST',
      url: "test.php",
      dataType: 'json',
      success: function (data) {
          var arr = [];
          for (var i = 0; i &lt; data.length; i++) {
              arr[data[i].type][data[i].age] = data[i].ammount;
          }
      }
  });
  </code></pre>
  
  <p>The idea is to get array that looks like this:</p>
  
  <pre><code>arr[def][1] = 2
  arr[def][2] = 4
  arr[def][3] = 13
  arr[abc][1] = 1
  arr[abc][2] = 0 // note that this one is just empty because it was not declared from json data.
  </code></pre>
  
  <p>Unfortunately I get an error: </p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot set property '1' of undefined</p>
  </blockquote>
  
  <p>1 is <code>[data[i].age]</code> and if I change its value error appears with other number.</p>