I'm trying to find the number of total occurrences of a word in an array.
Here I found a solution and altered it a bit:
var dataset = ["word", "a word", "another word"];
var search = "word";
var count = dataset.reduce(function(n, val) {
return n + (val === search);
}, 0);
But, instead of 3 I only get 1. So it only finds the first element, which is just word
. But how to find all elements, containing word
?