Three Ways to Title Case a Sentence in JavaScript
Sonya Moisset

Really nice way to get it sorted. I did with substrings and a lot o variables. Really ugly. I loved the way you reassign the value of the words in the array, I pasted my code here, and I am glad to study yours…. I hope the next time I can do a neat code like yours.


function titleCase(str) {
 var lowerCasing = str.toLowerCase().split(“ “); 
 var capitalized = [];
 for(i = 0; i < lowerCasing.length; i++){
 var rest = lowerCasing[i].charAt(0).toUpperCase() + lowerCasing[i].substring(1).toLowerCase();
 return capitalized.join(“ “);

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

Like what you read? Give Felipe Costa a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.