How to count all objects in array that match a condition with TypeScript

1 Answer

0 votes
const arr = [{lang: 'typescript'}, {lang: 'typescript'}, {lang: 'nodejs'}, {lang: 'typescript'}];
 
const count = arr.filter(obj => {
    if (obj.lang == 'typescript') {
        return true;
    }
    return false;
}).length;
 
console.log(count); 
   
   
   
   
/*
run:
   
3
   
*/

 



answered May 8, 2022 by avibootz
...