Answers for "javascript' input capitalize first letter of each word"

98

none

//capitalize only the first letter of the string. 
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}
//capitalize all words of a string. 
function capitalizeWords(string) {
    return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
Posted by: Guest on July-22-2019
0

capitalize first letter of all word typescript

//Altered, "capitalize all words of a string" (javascript by Grepper on Jul 22 2019) answer to compatible with TypeScript

var myString = 'abcd abcd';

capitalizeWords(text){
  return text.replace(/(?:^|\s)\S/g,(res)=>{ return res.toUpperCase();})
};

console.log(capitalizeWords(myString));

//result = "Abcd Abcd"
Posted by: Guest on November-18-2020

Code answers related to "javascript' input capitalize first letter of each word"

Code answers related to "Javascript"

Browse Popular Code Answers by Language