title: Removing Multiple Objects from Javascript Array Breaks Half Way Through
body: <p>I have an Array of a few hundred JSON Objects...</p>
  
  <pre><code>var self.collection = [Object, Object, Object, Object, Object, Object…]
  </code></pre>
  
  <p>Each one looks like this...</p>
  
  <pre><code>0: Object
     id: "25093712"
     name: "John Haberstich"
  </code></pre>
  
  <p>I'm iterating through the Array searching each Array.id to see if it matches any ids in a second Array...</p>
  
  <pre><code>   var fbContactIDs = ["1072980313", "2502342", "2509374", "2524864", "2531941"] 
  
     $.each(self.collection, function(index, k) {
          if (fbContactIDs.indexOf(k.id) &gt; -1) {
              self.collection.splice(index, 1);
          };
      });
  </code></pre>
  
  <p>However this code only works to splice three of the Objects from the self.collection array and then it breaks and gives the following error:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'id' of undefined 
  </code></pre>
  
  <p>The line that is causing the error is this one...</p>
  
  <pre><code>if (fbContactIDs.indexOf(k.id) &gt; -1) {
  </code></pre>
  
  <p>Could anyone tell me what I'm dong wrong here?</p>