Quantcast
Viewing latest article 28
Browse Latest Browse All 43

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

       var myString = "This is a string.";        var foundAtPosition = 0;        var Count = 0;        while (foundAtPosition != -1)        {            foundAtPosition = myString.indexOf("is",foundAtPosition);            if (foundAtPosition != -1)            {                Count++;                foundAtPosition++;            }        }        document.write("There are "+ Count +" occurrences of the word IS");

Refer :- count a substring appears in the string for step by step explanation.


Viewing latest article 28
Browse Latest Browse All 43

Trending Articles



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