问题:与对象数组进行比较和对象

时间:2016-07-08 09:10:44

标签: javascript angularjs node.js

我有一个场景,我需要将名为'name'的对象属性与具有相同名称的字符串数组进行比较,并根据名称获取比较值的长度。我不明白我需要比较什么。

以下是我的代码:

$scope.pushRec=[];
   //----comparing response and response.club properties
    angular.forEach($scope.aResponse, function(value, key) {
        $scope.aClub=value.club;
        console.log($scope.aClub);
        console.log(value.recruiter);
        $scope.aResRec=value.recruiter;
    });
    //----if it matches push in to pushRec
     angular.forEach($scope.aClub, function(value, key) {

        console.log(value.recruiter);
        $scope.aRec=value.recruiter;
           console.log($scope.aClub);
        if($scope.aResRec[0] ==  $scope.aRec){
            $scope.pushRec.push( $scope.aClub);
            console.log( $scope.pushRec.length);
        }

    });

1 个答案:

答案 0 :(得分:0)

你应该这样写。

 $scope.pushRec=[];
   //----comparing response and response.club properties
    angular.forEach($scope.aResponse, function(value, key) {
        $scope.aClub= angular.copy(value.club);
        console.log($scope.aClub);
        console.log(value.recruiter);
        $scope.aResRec=angular.copy(value.recruiter);
    });
    //----if it matches push in to pushRec
     angular.forEach($scope.aClub, function(value, key) {

        console.log(value.recruiter);
        $scope.aRec=value.recruiter;
           console.log($scope.aClub);
        if($scope.aResRec[0] ===  $scope.aRec){
            $scope.pushRec.push( $scope.aClub);
            console.log( $scope.pushRec.length);
        }

    });