Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

indexof all occurrences javascript

function countOccurences(string, word) {
   return string.split(word).length - 1;
}
var text="We went down to the stall, then down to the river."; 
var count=countOccurences(text,"down"); // 2
 
PREVIOUS NEXT
Tagged: #indexof #occurrences #javascript
ADD COMMENT
Topic
Name
4+7 =