2016-07-28 45 views
0

我有一个数组$scope.blinkingBoxes=[1,3,2]Angularjs检查两个阵列具有不同的元素

我有另一个数组称为$scope.clickedBoxes和我在它推几个值。如果

现在if(angular.equals($scope.blinkingBoxes, $scope.clickedBoxes)){doSomething()}检查两个阵列是相同的(在相同的顺序,即相同的元件)

但是我要检查,如果第二阵列不包含从第一阵列的任何元件,并执行一些动作。 我该如何做到这一点?

+0

重复? http://stackoverflow.com/questions/16312528/check-if-an-array-contains-any-element-of-another-array-in-javascript – fdelia

+0

它说'任何'元素,我想'无' – Nitish

回答

1

没有这样的内置功能

您可以使用此

angular.forEach(array1, function(value, key) { 
angular.forEach(array2, function(value_1, key_1) { 
    if (value === value_1) { 
     // condition or action 
    } 
}); 

});

0
count = 0; 
angular.forEach($scope.blinkingBoxes, function(value, key) { 
    if(value.indexOf($scope.clickedBoxes) == -1) { 
     //not in same order or not same elements action goes here 
     count++; 
    } 
}); 

if(count == $scope.blinkingBoxes.length) { 
    //second array do not contain any element from first array, action goes here 
} 
相关问题