Skip to content

Latest commit

 

History

History
7 lines (5 loc) · 243 Bytes

count-occurrences-of-a-value-in-array.md

File metadata and controls

7 lines (5 loc) · 243 Bytes

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;