How to count the true values in an array with JavaScript

1 Answer

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

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

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

  
  
 

 



answered May 7, 2022 by avibootz
...