Count Capital letters from a string in javascript:
var text = 'Raju Kumar Yadav';
var totalCapLetter = count(text );
function count(str){
var strArr = (str.match(/[A-Z]/g) || []);
return strArr.length;
}
console.log(totalCapLetter );
Output:
3
var text = 'Raju Kumar Yadav';
var totalCapLetter = count(text );
function count(str){
var strArr = (str.match(/[A-Z]/g) || []);
return strArr.length;
}
console.log(totalCapLetter );
Output:
3
Comments
Post a Comment