How to count how many times an element appears in array with JavaScript

1 Answer

0 votes
const arr = [4, 1, 2, 8, 9, 5, 5, 1, 7, 8, 8];
        
let count = 0;

arr.forEach(element => {
  	if (element === 8) {
    	count += 1;
  	}
});

console.log(count); 


      
      
/*
run:
      
3
        
*/

 



answered Jun 28, 2022 by avibootz
...