Files
30-seconds-of-code/snippets/count-occurrences-of-a-value-in-array.md
Darren Scerri b75b9c3fb6 Fix typos
Fix typos
2017-12-11 23:31:54 +01:00

243 B

Count occurrences of a value in array

Use filter() to create an array containing only the items with the specified value, count them using length.

var countOccurrences = (arr, value) => arr.filter(v => v === value).length;