title: array.splice removing values from remaining elements
body: <p>I ran across this strange side effect of array.splice, and distilled the code down to the minimum necessary to recreate.  Yes, much of this could be done on one line with array.filter, but I'm interested in whether I've made a mistake or if something else is going on.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var array = [];
  
  for (var i = 0; i &lt; 10; i++) {
    array.push({
      value: i
    });
  }
  
  array.forEach(function(item, index, intArray) {
    if (item.value % 2 == 1) {
      item.odd = true;
    } else {
      item.odd = false;
    }
  
    if (item.odd) {
      console.log("Removing " + item.value);
      intArray.splice(index, 1);
    }
  
  });
  
  console.log(array);</code></pre>
  </div>
  </div>
  </p>
  
  <p>Running this javascript results in the odd elements being removed as expected, but it also removed the item.odd values for items 2, 4, 6, and 8.  Removing the intArray.splice line brings back the odd array elements, but it also brings back the item.odd values for all elements.  </p>
  
  <p>I've tested this in FF and Chrome.  The behavior persists even if only the item is passed into the callback, with the index calculated via array.indexOf, and referencing the array from outside the loop.  </p>