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};
1function capitalizeName(name) {
2 return name.replace(/\b(\w)/g, s => s.toUpperCase());
3}
4
5
1//Updated
2//capitalize only the first letter of the string.
3function capitalizeFirstLetter(string) {
4 return string.charAt(0).toUpperCase() + string.slice(1);
5}
6//capitalize all words of a string.
7function capitalizeWords(string) {
8 return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
9};
1myString = 'the quick green alligator...';
2myString.replace(/^\w/, (c) => c.toUpperCase());
3
4myString = ' the quick green alligator...';
5myString.trim().replace(/^\w/, (c) => c.toUpperCase());
1const capitalizeFirstLetter(string) =>
2 string.charAt(0).toUpperCase() + string.slice(1).toLowerCase()
1function capitalize(paragraph) {
2 const paragraphCleaned = paragraph.replace(/\s{2,}/, " ")
3 const paragraphSplitted = paragraphCleaned.split(" ")
4 const capitalized = paragraphSplitted.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
5 return capitalized.join(" ")
6}