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 toTitleCase(str) {
2 return str.replace(/\w\S*/g, function(txt){
3 return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
4 });
5}
1const capitalizeFirstLetter(string) =>
2 string.charAt(0).toUpperCase() + string.slice(1).toLowerCase()
1const str = "HERE'S AN UPPERCASE PART of the string";
2const upperCaseWords = str.match(/(\b[A-Z][A-Z]+|\b[A-Z]\b)/g);
3
4console.log(upperCaseWords);