title: Pushing object literals into an array (repeating itself..)
body: <p>I don't think this is really an angular question, although I stumbled upon the problem while working with an angular ng-repeat directive.</p>
  
  <p>I'm trying to store javascript object literals into an array using push so I can iterate through that in ng-repeat.</p>
  
  <p>For example:</p>
  
  <pre><code>$scope.items = [];
  
  var item = {
     name: "bob"
  };
  
  $scope.items.push(item);
  item.name = "mary";
  $scope.items.push(item);
  </code></pre>
  
  <p>At this point, the $scope.items[] is holding 2 instances of the name Mary, instead of having both Bob and Mary. This is counter-intuitive as I thought push was supposed to just append the next item to the end of the array.</p>
  
  <p>My real code (summarized) goes something like the below:</p>
  
  <pre><code>$scope.items = [];
  
  var item = {
     name: "";
  };
  
  for (var i = 0; i &lt; 10; i++) {
     // I dynamically set the item.name to some value using retrieved values from server
     item.name = someValueFromServer;
  
     $scope.items.push(item);
  }
  </code></pre>
  
  <p>So, again, at the end of the for-loop, instead of having 10 different names, I have the SAME 10 names of the LAST one that was retrieved.</p>
  
  <p>I couldn't quite figure out how to solve this, and wasn't able to find anything online either. I'm fairly new to this so it might've been I was searching for the wrong thing.</p>
  
  <p>Any help would be awesome. Thanks so much!</p>