Count the number of true members in an array of boolean values Count the number of true members in an array of boolean values arrays arrays

Count the number of true members in an array of boolean values


Seems like your problem is solved already, but there are plenty of easier methods to do it.

Excellent one:

.filter(Boolean); // will keep every truthy value in an array

const arr = [true, false, true, false, true];const count = arr.filter(Boolean).length;console.log(count);