user1650978 user1650978 - 3 months ago 22
AngularJS Question

Check for multiple values in array object - AngularJS

I have the following :

$scope.Items = [{"ItemId": 1, "ItemName":"Test1"}, {"ItemId": 2, "ItemName":"Test2"}, {"ItemId": 3, "ItemName":"Test3"}];

If I wish to check if ItemId 1 AND ItemId 2 exist within this, what would be the best approach for it? I believe the
property should work, but how can it be used to check if a particular attribute value of the object exists within the array?


you can use like also

angular.forEach($scope.Items, function (value, key) {
            if (value.ItemId== 1) { $scope.firstitem=true; }
            if (value.ItemId== 2) { $scope.seconditem=true; }