title: How to compare two different arrays of objects declared in two different functions in angularjs?
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var app2 = angular.module("webApp2", [])
      .controller("webCtrl2", function ($scope, $state, $http) {
          console.log("hi");
          $scope.username = $state.params.username;
          console.log("shbsdjh" + $scope.email)
          $scope.userId = $state.params.userid;
          $scope.requests = [];
          var addedList = [];
  
          //Getting requests list:
          $http.get("http://192.168.2.3:3000/userslist")
              .then(function (response) {
                  console.log("hi", JSON.stringify(response));
                  $scope.requests = response.data;
              }, function (response) {
                  console.log("error" + response);
              });
  
          $scope.addfrnd = function (reqname, index) {
              console.log("shgsgh" + reqname);
              var data = {
                  userId: $scope.userId,
                  requestname: reqname,
                  username: $scope.username
              }
              var req = {
                  method: 'POST',
                  url: 'http://192.168.2.3:3000/friendrequests',
                  data: data
              }
              $http(req).then(function (response) {
                  console.log("saghdha" + JSON.stringify(response.data));
                  //..........................................................................................
                  //Gettind added list
                  $http.get("http://192.168.2.3:3000/sendfriendrequests/" + $scope.username)
                      .then(function (response) {
                          console.log("added list" + JSON.stringify(response));
                          addedList = JSON.stringify(response.data.username);
                          console.log("addedlist" + addedList)
                      }, function (response) {
                          console.log("error" + response);
                      });
                  //..........................................................................................
  
              }, function (response) {
                  console.log(response);
              });
          }
          console.log("uname" + addedList);
          $scope.logoutFn = function () {
              $state.go("signup");
          }
  
      });</code></pre>
  </div>
  </div>
  </p>
  
  <p>Iam working with chat application.Here Iam getting userslist and send request list using APIs.In the userslist API,an array list of people will get and in send request API,an array list of people to those I have send the request will be present.Now I have to compare the these two arrays containing objects inorder to remove the people to those the request is send in the userslist.Iam strucked at implementing the code in angularjs for comparison of these two arrays declared in two different functions.Please help me..
  This is my javascript code:</p>