title: Assign array values in each loop
body: <p>I'm trying to loop through input fields with an each loop, add other form data to an array and then add that input value to the form data already in the array.</p>
  
  <p>It seems to be basically working but every time I set the input it sets that value in all the entries with that name in the array.  Any ideas about where my logic is going sideways?</p>
  
  <pre><code>$(this).next('tr').children('td').each(function () {
          input = $(this).children('input');
          units[i] = unit;
          units[i]['barcode'] = input.val();
          i++;
   });
  </code></pre>
  
  <p>Output object:
   Object {0: Object, 1: Object}
  0: Object
  barcode: "789"
  qty: "3"
  size: 15
  status: "received"</p>
  
  <p>1: Object
  barcode: "789"
  qty: "3"
  size: 15
  status: "received"</p>
  
  <p>The input.val() is different on each iteration of the each loop, it just assigns the last value to all barcode entries.</p>