Files
30-seconds-of-code/snippets/count-occurrences-of-a-value-in-array.md

8 lines
243 B
Markdown

### 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`.
```js
var countOccurrences = (arr, value) => arr.filter(v => v === value).length;
```