title: Using splice with nested arrays in Javascript
body: <p>I have an array in which all the elements are also arrays (of integers), called <code>mainArray</code>.
  I am trying to use <code>splice()</code> to add and remove its elements (subarrays).</p>
  
  <p>Initially <code>mainArray</code> has a single element (an Array with one integer), I wish to delete it and add 3 new subarrays to <code>mainArray</code>, these are defined in arraysToAdd.</p>
  
  <pre><code>mainArray = new Array(new Array(1));
  arraysToAdd = new Array(new Array(1,2), new Array(1,4), new Array(1,7));
  
  alert(arraysToAdd.length); // Returns: 3: as expected
  
  mainArray.splice(0,1,arraysToAdd);
  
  alert(mainArray.length); // Returns: 1: I want this to be 3
  </code></pre>
  
  <p>I expect the length of <code>mainArray</code> at the end to be 3 (as it should contain 3 subarrays), but it seems <code>splice()</code> is flattening <code>arraysToAdd</code> and so <code>mainArray</code> ends up just being an array of integers.</p>
  
  <p>What am I missing?</p>