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 lower = 'this is an entirely lowercase string';
2const upper = lower.charAt(0).toUpperCase() + lower.substring(1);
1const name = 'flavio'
2const nameCapitalized = name.charAt(0).toUpperCase() + name.slice(1)
3
1const string = "tHIS STRING'S CAPITALISATION WILL BE FIXED."
2const string = string.charAt(0).toUpperCase() + string.slice(1)
1function capitalizeFirstLetter(name) {
2 return name.replace(/^./, name[0].toUpperCase())
3}
1const titleCase = title => title
2 .split(/ /g).map(word =>
3 `${word.substring(0,1).toUpperCase()}${word.substring(1)}`)
4 .join(" ");