Hi i am trying to find the sum of Boolean values in the object array in JavaScript
My json like be
var myoBj = [{
"id": 1,
"day": 1,
"status": true
}, {
"id": 2,
"day": 1,
"status": false
}, {
"id": 3,
"day": 1,
"status": false
}, {
"id": 4,
"day": 3,
"status": false
}];
i want the sum of all status values using reduce function in JavaScript/ typescript
i want to show overall status as true only when all status are true else it should be false
If you must use
reduce
you can take advantage of the fact thatx*false == 0
, and so you can do the following:This should return true, if every value is true.
If you want to sum lets say,
day
items value depending on thestatus
flag, this can looks like:Update 1
For overall status in case of all statuses are true you should use every method: