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};
1'ThisIsTheStringToSplit'.split(/(?=[A-Z])/); // positive lookahead to keep the capital letters
2
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};
1const capitalizeFirstLetter(string) =>
2 string.charAt(0).toUpperCase() + string.slice(1).toLowerCase()