title: pushing data into array inside a for loop JavaScript
body: <p>Could someone give me an explanation as to why this works</p>
  
  <pre><code>itemIds = [];
  for (var i = 0; i &lt;= data.length; i++) {
    itemIds.push(data[0].item);
  }
  console.log(itemIds); // outputs as expected, the same thing, data.length times
  </code></pre>
  
  <p>But this does not work (the only change is adding <code>i</code> into the <code>push()</code>)</p>
  
  <pre><code>itemIds = [];
  for (var i = 0; i &lt;= data.length; i++) {
    itemIds.push(data[i].item);
  }
  console.log(itemIds); // TypeError: Cannot read property 'item' of undefined
  </code></pre>
  
  <p>I need to do this as <code>data</code> in this example is coming from an angular <code>$http</code> call, and returning an object. I don't understand why statically putting in 0 works, but trying to make it iterate through each <code>data.item</code> does not.</p>