I've looked in many of the threads that discuss this, but maybe I'm just missing the concept. I have an array of objects that contain properties with values. I need to count a specific property in the array of objects only if it's value = true.
In the JSON below, I need to loop over every item in the array and then count only items where "IsPartyEnabled" evaluates to true. So, the count from the below JSON would = 3. I then need to return "3" back to my view.
FunToBeHad [{
"IsFunAllowed": true,
"IsPartyEnabled": true,
"IsJoyRefillable": true,
},{
"IsFunAllowed": true,
"IsPartyEnabled": false,
"IsJoyRefillable": true,
},{
"IsFunAllowed": true,
"IsPartyEnabled": true,
"IsJoyRefillable": true,
},{
"IsFunAllowed": true,
"IsPartyEnabled": true,
"IsJoyRefillable": true,
}]
I have tried this, but get stuck as I believe the property will still be undefined. Having no luck.
$scope.partyEnabled = function () {
for (var i = 0; i < $scope.FunToBeHad.length; ++i) {
if($scope.FunToBeHad[i].IsPartyEnabled = true ) {
return i;
}
}
};