title: Javascript putting values in two-dimensional array
body: <p>Is there a better way to create a two-dimensional array in javascript than this?</p>
  
  <pre><code>var divcookies = new Array();
  divcookies[0] = new Array(2);
  divcookies[0][0] = name;
  divcookies[0][1] = value;
  </code></pre>
  
  <p>This results in a two dimensional array with bad data added in the middle of it. I expect an array like this.</p>
  
  <pre><code>(name1, value1, name2, value2, name3, value3)
  </code></pre>
  
  <p>Instead I get this.</p>
  
  <pre><code>(name1, value2, ,name2, value2, name3, value3)
  </code></pre>
  
  <p>I don't really know when that extra bad data is added because if I alert during the loop that fills the array it only seems to loop through 3 times to put the three pairs of values expected.</p>
  
  <p>So I am looking for a different way to get the two dimensional array.</p>
  
  <pre><code>function get_cookies_array() {
  
      var divcookies = new Array();
  
      if (document.cookie &amp;&amp; document.cookie != '') {
          var split = document.cookie.split(';');
          for (var i = 0; i &lt; split.length; i++) {
              var name_value = split[i].split("=");
              name_value[0] = name_value[0].replace(/^ /, '');
              if ( name_value[0].search("compage") != -1 ) {
                 alert (divname+" "+ divarray);
                 divcookies[i] = new Array(2);
                 divcookies[i][0] = decodeURIComponent(name_value[0]);
                 divcookies[i][1] = decodeURIComponent(name_value[1]);
              }
          }
      }
  
      alert (divcookies);
  
      return divcookies;
  </code></pre>
  
  <p>}</p>
  
  <p>jsBin <a href="http://jsbin.com/iwuqab" rel="nofollow">http://jsbin.com/iwuqab</a></p>