title: Missing Logic in my code populating array creates duplicates - javascript
body: <p>i'm trying to figure out how to not duplicate objects in my array. Notice in the commentors data model, index 0 and 1 is duplicated because the insertproperty function i did an id compare which is ideal for a list with unique ids, but i still have to apply this in this situation to make sure im associating to the correct user. </p>
  
  <p>Comments Data Model: </p>
  
  <pre><code>var comments = [{id:1, comment_text:"foo", user_id:1},
  {id:2, comment_text:"bar", user_id:1},
  {id:3, comment_text:"brew", user_id:2}];
  </code></pre>
  
  <p>Commentors Data Model when merged: </p>
  
  <pre><code>var commentors = [{id:1, name:"ed", comment_text:"foo"},
  {id:1, name:"ed", comment_text:"foo"},
  {id:2, name:"sue", comment_text:"brew"}];
  </code></pre>
  
  <p>DESIRED Result:</p>
  
  <pre><code>var commentors = [{id:1, name:"ed", comment_text:"foo"},
  {id:1, name:"ed", comment_text:"bar"},
  {id:2, name:"sue", comment_text:"brew"}];
  </code></pre>
  
  <hr>
  
  <pre><code>$scope.insertProperty=function(){           
          for(var i=0;i&lt;$scope.commentors.length;i++){
              for(var j=0;j&lt;$scope.comments.length;j++){
                  if($scope.commentors[i].id==$scope.comments[j].user_id)                               
                  $scope.commentors[i].comment_text=$scope.comments[j].comment_text;                   
              }
          }
      }
  
  $scope.commentors = [];
    var getUser = function(id) {
          UserService.GetUserById(id, $localStorage.CurrentUser.auth_token)
          .success(function (data) {
            var data = angular.fromJson(data);   
            $scope.commentors.push(data);
            $scope.insertProperty();
          }).error(function(error, status) {
              //do something         
          });
      };
  
  $scope.GetComments = function(){
  PostService.GetComments($stateParams.id, $localStorage.auth_token)
            .success(function (data) {      
              var data = angular.fromJson(data);                 
              angular.forEach(data, function(user){
                  getUser(user.user_id);})                       
            }).error(function(error, status) {
              //do something        
            });
      }
  </code></pre>