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 277 views
1 answer 206 views
1 answer 293 views
2 answers 304 views
1 answer 215 views
...