How to count all objects in array that match a condition with Node.js

1 Answer

0 votes
const arr = [{lang: 'nodejs'}, {lang: 'c++'}, {lang: 'nodejs'}, {lang: 'nodejs'}, {lang: 'nodejs'}];

const count = arr.filter(obj => {
  if (obj.lang == 'nodejs') {
    return true;
  }

  return false;
}).length;

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

 



answered May 8, 2022 by avibootz
...