Files
30-seconds-of-code/snippets/count-occurences-of-a-value-in-array.md
Angelos Chalaris f40115ff3b Swap, anagrams, occurences
Fixed sorting title for strings.
2017-12-06 23:50:23 +02:00

241 B

Count occurences of a value in array

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

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