title: Difference splicing between Array() and [] in Javascript
body: <p>I am trying to replicate Python's insert at index functionality in Javascript.</p>
  
  <pre><code>var index = [0,1,2,3,4]
  var nums = [0,1,2,2,1]
  
  const target = new Array(nums.length);
  
  for (let i=0; i&lt;index.length; i++) {
    target.splice(nums[i], 0, index[i]);
  };
  
  console.log(target);
  </code></pre>
  
  <p>This produces the following output:</p>
  
  <blockquote>
    <p>[ 0, 4, 1, 3, 2, &lt;5 empty items> ]</p>
  </blockquote>
  
  <p>However, if I run the following code:</p>
  
  <pre><code>var index = [0,1,2,3,4]
  var nums = [0,1,2,2,1]
  
  const target = [] //new Array(nums.length);
  
  for (let i=0; i&lt;index.length; i++) {
    target.splice(nums[i], 0, index[i]);
  };
  
  console.log(target);
  </code></pre>
  
  <p>This produces the following output:</p>
  
  <blockquote>
    <p>[ 0, 4, 1, 3, 2 ]</p>
  </blockquote>
  
  <p>What is going on? The second output is the one I desire.</p>