How to count the true values in an array with TypeScript

1 Answer

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

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

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

 



answered May 7, 2022 by avibootz
...