Digital programming is a blog for developers & coding enthusiastic people. It provides a lot of solutions & strategies of coding in simplistic way.
Program:
//method definition
function countString(str, chr){
var count = 0;
for(var k=0; k < str.length; k++){
if(str.charAt(k) === chr){
count++;
}
return count;
//method call
countString("Hello World", "l");
Output:
3
No comments:
Post a Comment