Three Ways to Title Case a Sentence in JavaScript
Sonya Moisset
20221

didn't think this would work, but it did, how practical would this be?

function titleCase(str) {
 str = str.toLowerCase();
 return str.replace(/\b\w(?!\s)/g, function(f) { // ‘f’ for (first letter) of occurrence/pattern
 return f.toUpperCase();}).replace(/\s.\s/g,function(l) { // ‘l’ for (single letter pattern)
 return l.toUpperCase();}); 
}

titleCase(“I’m a little tea pot”);

Show your support

Clapping shows how much you appreciated Brien Smarandache’s story.