Advertisement
728x90
Title case means that the first letter of each word is capitalized. You can convert a string to title case using the below function,
javascript
1function toTitleCase(str) {
2 return str.replace(/\w\S*/g, function (txt) {
3 return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
4 });
5 }
6
7toTitleCase("good morning john"); // Good Morning JohnAdvertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 12
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
183of476