Skip to content

Instantly share code, notes, and snippets.

@mansouryaacoubi
Created February 22, 2018 15:58
Show Gist options
  • Save mansouryaacoubi/091c4582623faf300931b15da5953319 to your computer and use it in GitHub Desktop.
Save mansouryaacoubi/091c4582623faf300931b15da5953319 to your computer and use it in GitHub Desktop.
Find amount of occurrences of value in array (Javascript)
Array.prototype.occurrences = function(val) {
var i = 0, c = 0;
while( (i = this.indexOf(val,i)+1) && ++c );
return c;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment