javascript - how to get the count of boolean value(if it is true) in array of objects -


i have count of boolean value(if true) in array of objects. json structure given below:

[   {     "id": 5,     "name": "a",     "select": true   },    {     "id": 3,     "name": "b",     "select": false   },    {     "id": 2,     "name": "x",     "select": true   },    {     "id": 1,     "name": "y",     "select": false   } ] 

you can using array.prototype.filter()

try this

console.log(data.filter((x,i) => { return x.select; }).length) 

demo


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -