Js 判断一个字符串中某个字符的个数(正则)

let str = 'abbbdsscc';
// match 方法返回匹配的数组
let res = str.match(/b/g);
let count = !res ? 0 : res.length;
console.log(count)

参考:https://zhidao.baidu.com/question/203645176591981045.html

posted @ 2020-11-30 22:18  公瑾当年  阅读(4429)  评论(0编辑  收藏  举报