📜  javascript 计数字符串中的实例 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:32.411000             🧑  作者: Mango

代码示例1
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