Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
108
rated 0 times [  111] [ 3]  / answers: 1 / hits: 18928  / 8 Years ago, thu, january 19, 2017, 12:00:00

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


More From » arrays

 Answers
8
var result = myObj.reduce((sum, next) => sum && next.status, true);


This should return true, if every value is true.


[#59287] Wednesday, January 18, 2017, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
josefn

Total Points: 251
Total Questions: 93
Total Answers: 84

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
;