Javascript String occurences_of(str)
// 'use strict'; // use it to get direct result for this in prototype binding String.prototype.occurences_of = function(str){ var occ = (temp.match(/is/g) || []).length; return occ;/*w w w . j a v a 2 s . co m*/ } var temp = "This is a string."; console.log(temp.occurences_of("is"));