How to count string occurrence in string?

Answer

var temp = "This is a string.";

// the g in the regular expression says to search the whole string
// rather than just find the first occurrence
var count = (temp.match(/is/g) || []).length;

alert(count);

All string Questions

Ask your interview questions on string

Write Your comment or Questions if you want the answers on string from string Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---