Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravivit9/6e5b2f10d8dd89453739e5fa01308acf to your computer and use it in GitHub Desktop.
Save ravivit9/6e5b2f10d8dd89453739e5fa01308acf to your computer and use it in GitHub Desktop.
Search for a string value from an array of items and return those matching array items.
var dataset = [2,2,4,2,6,4,7,8];
var search = 2;
var count = dataset.reduce(function(n, val) {
return n + (val === search);
}, 0);
console.log(count);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment