Every line of 'javascript count occurrences in string' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
299 function occurrences(string, subString) { 300 var n = 0, pos = 0, step = subString.length 301 302 while (true) { 303 pos = string.indexOf(subString, pos) 304 if (pos >= 0) { 305 n++ 306 pos += step 307 } 308 else break 309 } 310 return n 311 }