typescript first letter uppercase code example
Example 1: javascript capitalize words
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function capitalizeWords(string) {
return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
Example 2: javascript capitalize first letter
const lower = 'this is an entirely lowercase string';
const upper = lower.charAt(0).toUpperCase() + lower.substring(1);
Example 3: capitalize first letter of all word typescript
var myString = 'abcd abcd';
capitalizeWords(text){
return text.replace(/(?:^|\s)\S/g,(res)=>{ return res.toUpperCase();})
};
console.log(capitalizeWords(myString));