Quantcast
Viewing latest article 32
Browse Latest Browse All 43

Answer by Gere for How to count string occurrence in string?

My solution:

var temp = "This is a string.";function countOccurrences(str, value) {  var regExp = new RegExp(value, "gi");  return (str.match(regExp) || []).length;}console.log(countOccurrences(temp, 'is'));

Viewing latest article 32
Browse Latest Browse All 43

Trending Articles