DEV Community

Discussion on: An easy way to count elements in a JavaScript array

Collapse
 
frankwisniewski profile image
Frank Wisniewski
let names = ["David","Walsh","David","Tania","Lucretius"];
names.filter(x=>x==="David").length // => 2
Enter fullscreen mode Exit fullscreen mode
Collapse
 
orashus profile image
Rash Edmund Jr

clean and short πŸ™‚

Collapse
 
lubiah profile image
Lucretius Biah

Hey @frankwisniewski,
You method is much simpler. I guess I will have to update my code.
Anyways, thanks for the helpπŸ₯³πŸ₯³