title: How to match the KeyId,if keyId will be match remove from array in AngularJS?
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>        /**
           * @Summary: setUserAccessB  function, to get detail of the shared product.
           * @param: event, index, userObj
           * @return: callback(response)
           * @Description:
           */
          $scope.buyerObjectList            = [];
          $scope.productDBList              = [];
          $scope.productObjectForShareModal = null;
  
          $scope.countConnectedBuyer  = 0;
          $scope.setUserAccessB = function(index, isChecked, keyId) {
            if(isChecked) {
              $scope.buyerObjectList.push(keyId);
              $scope.countConnectedBuyer ++;
            } else {
              var index = $scope.buyerObjectList.indexOf(keyId);
              $scope.buyerObjectList.splice(index, 1);
              $scope.countConnectedBuyer --;
            }
          }
  
              /**
               * @Summary: checkAllConnectedUser function, to create album
               * @param: index, productObj
               * @return: callback(response)
               * @Description:
               */
              $scope.checkAllBuyerKeyId      = [];
              $scope.buyerObj                = [];
              $scope.intermediaryObjectList  = [];
              $scope.checkAllConnectedUser = function(isChecked) {
                if(isChecked) {
                  if ($scope.selectedAll) {
                    $scope.selectedAll = false;
                  } else {
                    $scope.selectedAll = true;
                  } 
                  angular.forEach($scope.buyerRelationDtoForModal.buyerDtos, function (buyerObj) {
                    buyerObj.select = $scope.selectedAll;
                    //IF ID WILL BE EXIST IN THE ARRAY NOT PSUH THE KEYID
                    if($scope.buyerObjectList.indexOf(buyerObj.userTypeDto.keyId) == -1) {
                      $scope.buyerObjectList.push(buyerObj.userTypeDto.keyId);
                      $scope.countConnectedBuyer ++;
                    }
                  });
  
                 } else {
                    $scope.selectedAll  = false;
                    //USED FOR UNCHECK ALL THE DATA ONE- BY-ONE
                    angular.forEach($scope.buyerRelationDtoForModal.buyerDtos, function (buyerObj) {
                      buyerObj.select = $scope.selectedAll;
                      var index = $scope.buyerObjectList.indexOf(buyerObj.userTypeDto.keyId);
                      $scope.buyerObjectList.splice(index, 1);
                      if($scope.buyerObjectList.length == 0) {
                        $scope.countConnectedBuyer = 0;
                      } else {
                        $scope.countConnectedBuyer --;
                      }
                    });
                  }
               }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="buyer" class="w3-container userSection"&gt;
    &lt;div class="checkbox w3-margin" ng-if="buyerRelationDtoForModal.buyerDtos.length &gt; 0"&gt;
        &lt;label&gt;
          &lt;input type="checkbox" ng-model="selectedAll"  ngclick="checkAllConnectedUser(selectedAll)"/&gt;Check All
        &lt;/label&gt;
        &lt;span class="w3-right" ng-if="countConnectedBuyer"&gt;
          &lt;h5&gt;You are selecting {{countConnectedBuyer}} buyers!&lt;/h5&gt;
        &lt;/span&gt;
      &lt;/div&gt;
        &lt;div class="w3-row userObjRow" ng-repeat="buyerObj in buyerListTemp = (buyerRelationDtoForModal.buyerDtos) track by $index" 
          ng-if="checkIfBuyerIsSharedAlready(buyerObj.keyId) &amp;&amp; buyerObj.userAccessType == 'private'"&gt;
          &lt;div class="col-md-10 col-sm-10 productDetailsWrap item_info" &gt;
            &lt;div class="w3-row ng-cloak"&gt;
              &lt;div class="checkbox"&gt;
                &lt;label id="shareUserSection"&gt;
                  &lt;input type="checkbox" ng-model="buyerObj.select" 
                    ng-click ="setUserAccessB($index, buyerObj.select, buyerObj.userTypeDto.keyId)"/&gt;
                    &lt;i class="glyphicon glyphicon-user w3-text-black"&gt;&lt;/i&gt;
                      {{buyerObj.personName}} 
                    &lt;span class="w3-text-teal"&gt;
                      {{buyerObj.userTypeDto.userTypeAddressDtos[0].city}}
                    &lt;/span&gt;  
                &lt;/label&gt; -&amp;nbsp; 
                &lt;span class="w3-tag w3-teal w3-round w3-small"&gt;
                  &amp;nbsp;{{buyerObj.userTypeDto.userType}}
                &lt;/span&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
         &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have to share product with user and I have to list- 1st connected user list for share product with user and 2nd is the shared user list(shared product list) if I have click on  the  check all checkbox here all checkbox will be check but at time I have to remove 1 user at  a time and click on the shared user list.now again I click on the check all checkbox here only 1 user found and I will get 1 update user but here I will be found all user again because I have iterate all the list again, 
  angular.forEach($scope.buyerRelationDtoForModal.buyerDtos) - here I will remove the match keyID and updated the 1 user how  to resolve this issue?</p>