Title case means that the first letter of each word is capitalized. You can convert a string to title case using the below function:
1 2 3 4 5 6 7 8 9 10 11 | function toTitleCase(str) { return str.replace( /\w\S*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); } ); } // Good Morning John toTitleCase("good morning john"); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.