How to find number of dots from string using Javascript

Find number of dots from string using javascript

By using this function we can get the no of repeated character from the string using java script.
function count(s1, letter) {
    return s1.match( new RegExp(letter,'g') ).length;

Example 1:
  count('Yes. I want. to. place a. lot of. dots.','\\.'); //=> 
  output : 6
Example 2:
  count('2....3','\\.'); //=> 
  output : 4

posted under |


Post a Comment

Please provide your valuable comment.

Newer Post Home


Powered by Blogger.


Custom Search