javascript - Count the number of same values in array -


i have data in database below

vm.result = [ {   "_id": objectid("57c036a75f7635e80c5d5bc8"),   "sharedpersonid": objectid("570dec75cf30bf4c09679deb"),   "notificationdetails": [     {       "userid": "570dfae0e79bd384255b6471",       "username": "vinay",       "isred": true      }    ]  }, {   "_id": objectid("57bef418600b4350280f0b2f"),   "sharedpersonid": objectid("570dec75cf30bf4c09679deb"),   "notificationdetails": [     {       "userid": "56fe44836ce2226431f5388f",       "username": "hemanth",       "isred": true      }    ]   },  {    "_id": objectid("57bef1a1d985a82c24e0c49b"),    "sharedpersonid": objectid("570dec75cf30bf4c09679deb"),    "notificationdetails": [      {        "userid": "57443657ee5b5ccc30c4e6f8",        "username": "kevin",        "isred": true       }     ]    }                  ] 

to access isred, have used loop in angular.js file below

for(var key in vm.result){   for(var key1 in vm.result[key].notificationdetails){      console.log(vm.result[key].notificationdetails[key1].isred);   } } 

the result shows true true true isred contains possibilities of true , false. want count how number of true's there. how solve please me.

var truecount = 0; var falsecount = 0; for(var key in vm.result){   for(var key1 in vm.result[key].notificationdetails){      if(vm.result[key].notificationdetails[key1].isred){          truecount ++ ;      }else{          falsecount ++;      }   } } 

this way can keep track of true's , false's.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -