↧
Answer by Rebecca Chernoff for How to count string occurrence in string?
The g in the regular expression (short for global) says to search the whole string rather than just find the first occurrence. This matches is twice:var temp = "This is a string.";var count =...
View ArticleHow to count string occurrence in string?
How can I count the number of times a particular string occurs in another string. For example, this is what I am trying to do in Javascript:var temp = "This is a string.";alert(temp.count("is"));...
View ArticleAnswer by sachin sahu for How to count string occurrence in string?
let str="sachinsahu";let output={};for (var i = 0; i < str.length; i++) { console.log(str[i]); let ch=str[i]; if(!output[ch]){ output[ch]=1; } else{ output[ch]+=1; }}console.log(output);
View Article