title: How do I add (push) items to an array one at a time (looping through array)
body: <p>I can't figure this weird problem out. <a href="https://jsbin.com/posedu/edit?html,js,console,output" rel="nofollow noreferrer">Link to Jsbin</a></p>
  
  <p>I'm trying to add values to an array (<code>prices</code>), using a click function. When the user clicks a button, it adds pricing data to a Javscript array <code>prices</code>. </p>
  
  <p>I need to add multiple data entries at once, that contain the price but different <code>day</code>. </p>
  
  <p>This is my click function for #add_pricing. </p>
  
  <pre><code>$("#add_pricing").click(function(e){
      e.preventDefault();
      data = {
          "price": "1200",
          "days": ["1","3","4"]
      }
      addData(data);
      console.log(prices)
  });
  </code></pre>
  
  <p>So when the user clicks that, as you can see it sends the <code>data</code> variable to addData, which is: </p>
  
  <pre><code>function addData(data)
  {
      for (i = 0; i &lt; data.days.length; i++){
          data.day = data.days[i]; //eg. data.day = "1"
          prices.push(data);
  
      }
  }
  </code></pre>
  
  <p>So the <code>addData()</code> function loops through data.days and I want it to push an entry to the <code>prices</code> array, but one at a time. </p>
  
  <p>But instead it seems to push all 4 items at a time for every itteration (you can see if you log the output)</p>
  
  <p><img src="https://i.stack.imgur.com/2n9Ta.png" alt="enter image description here"></p>
  
  <p>AND it doesn't set my day variable properly, day is ALWAYS set to 4, even though if I log the output, it seems to be displaying the correct one.</p>
  
  <p><img src="https://i.stack.imgur.com/NVpMZ.png" alt="enter image description here"></p>
  
  <p>Expected output:</p>
  
  <pre><code>[1] =&gt; {day: 1, price: 1200}
  [2] =&gt; {day: 3, price: 1200}
  [3] =&gt; {day: 3, price: 1200}
  </code></pre>
  
  <p>Actual output</p>
  
  <pre><code>[1] =&gt; {day: 4, price: 1200}
  [2] =&gt; {day: 4, price: 1200}
  [3] =&gt; {day: 4, price: 1200}
  </code></pre>