统计某一字符或字符串在另一个字符串中出现的次数

  function strCount(str, target) {
   let count = 0
  if (!target) return count
  while(str.match(target)) {
     str = str.replace(target, '')
     count++
                          }
    return count
                        }

评论

暂无评论