title: JavaScript splice() undefined index on iteration
body: <p>I'm trying to delete item from array based on conditional.</p>
  
  <pre><code>var Stack  = {};
  
  Stack.items = [];
  
  Stack.items.push({
      id: '123',
      name: 'Lorem ipsum dolor sit.'
  });
  
  Stack.items.push({
      id: '154',
      name: 'Lorem ipsum dolor sit.'
  });
  
  Stack.items.push({
      id: '123',
      name: 'Lorem ipsum dolor sit.'
  });
  </code></pre>
  
  <p>Now, I'll delete all items with 154 id.</p>
  
  <pre><code>$.each(Stack.items, function(index, item) {
      // console.log( item.id );
      // console.log( index);
      if( item.id === '154' ) {
          Stack.items.splice(index, 1);
      }
  });
  </code></pre>
  
  <p>But I get an undefined error in the second iteration. I think this is because splice() function modified the original array so the indexes were altered</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'id' of undefined
  </code></pre>
  
  <p>I'm getting the expected results with lodash but i'm trying to not use them just for this issue</p>
  
  <pre><code>_.remove(Stack.items, function(item) {
      return item.id === '123';
  });
  </code></pre>
  
  <p>Thanks!!</p>