title: How to get objects with same key values with comma separated
body: <p>I have an array of objects , each object have key and value .I want if object have same keys then their values shoud be comma sepated of all the values of same key.
  my html code:</p>
  
  <pre><code>&lt;p ng-repeat="item in allOptions" class="item" id="{{item.id}}"&gt;
    {{item.id}} &lt;input type="checkbox" ng-change="sync(bool, item)" ng-model="bool" &gt;  {{item}} Selected: {{bool}} 
    &lt;/p&gt;
  </code></pre>
  
  <p>and my controller code is :</p>
  
  <pre><code> $scope.allOptions = [
      {
        "id": "1",
        "data": "one",
      },
      {
        "id": "1",
        "data": "two",
      },
      {
        "id": "2",
        "data": "three",
      },
    ];
  
    $scope.data = [
  
    ];
  
    $scope.sync = function(bool, item){
  
      if(bool){
        // add item
        $scope.data.push(item);
      } else {
        // remove item
        for(var i=0 ; i &lt; $scope.data.length; i++) {
          if($scope.data[i] == item.id){
            $scope.data.splice(i,1);
          }
        }      
      }
    };
  </code></pre>
  
  <p>In data array i have objects ,if we select same key of objects (same id value )then i want </p>
  
  <pre><code>{
            "id": "1",
            "data": "one","two",
          }
  </code></pre>