Quantcast
Channel: How to count string occurrence in string? - Stack Overflow
Viewing all articles
Browse latest Browse all 43

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

$
0
0

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 all articles
Browse latest Browse all 43

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>