How to count the true values in an array with Node.js

1 Answer

0 votes
const arr = [true, 'javascript', true, 'node.js', true, 'c++', true, false, true];

const count = arr.filter(value => value === true).length;

console.log(count); 
   
   
   
   
   
/*
run:
   
5
   
*/

 



answered May 7, 2022 by avibootz

Related questions

2 answers 276 views
1 answer 205 views
1 answer 292 views
2 answers 303 views
1 answer 213 views
...