Count chars in a String - Node.js String

Node.js examples for String:Char

Description

Count chars in a String

Demo Code


String.prototype.countChars = function( chr ) {
  for( var i = count = 0; i < this.length; i++ ) {
    if( this.charAt( i ) === chr ) {
      count++;/*w ww.  ja v  a  2  s  . co m*/
    }
  }
  return count;
}

Related Tutorials