[removed] How many times a character occurs in a string?

前端 未结 6 2100
傲寒
傲寒 2020-12-13 03:15

Is there a simple way to check how many times a character appears in a String?

6条回答
  •  别那么骄傲
    2020-12-13 03:49

    var s = "dqsskjhfds";
    alert(s.length - s.replace(/a/g, "").length); // number of 'a' in the string
    

提交回复
热议问题