📌  相关文章
📜  Javascript 计算字符串中字符的实例 - Javascript 代码示例

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

代码示例3
function countInstancesOf(letter, sentence) {
  var count = 0;

  for (var i = 0; i < sentence.length; i++) {
    if (sentence.charAt(i) === letter) {
      count += 1;
    }
  }
  return count;
}