1//capitalize only the first letter of the string.
2function capitalizeFirstLetter(string) {
3 return string.charAt(0).toUpperCase() + string.slice(1);
4}
5//capitalize all words of a string.
6function capitalizeWords(string) {
7 return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
8};
1const capitalizeText = (text) =>{
2 return text.toLowerCase().charAt(0).toUpperCase()+(text.slice(1).toLowerCase())
3}
1const name = 'flavio'
2const nameCapitalized = name.charAt(0).toUpperCase() + name.slice(1)
3
1const toCapitalCase = (string) => {
2 return string.charAt(0).toUpperCase() + string.slice(1);
3};
1myString = 'the quick green alligator...';
2myString.replace(/^\w/, (c) => c.toUpperCase());
3
4myString = ' the quick green alligator...';
5myString.trim().replace(/^\w/, (c) => c.toUpperCase());