Update and rename count-occurences-of-a-value-in-array.md to count-occurrences-of-a-value-in-array.md
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
### Count occurences of a value in array
|
### 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`.
|
Use `filter()` to create an array containing only the items with the specified value, count them using `length`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var countOccurences = (arr, value) => arr.filter(v => v === value).length;
|
var countOccurrences = (arr, value) => arr.filter(v => v === value).length;
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user