Three Ways to Title Case a Sentence in JavaScript
Sonya Moisset

I liked your explanation. Here is a slighltly different version of Method 1:

function titleCase(str) {
 str = str.toLowerCase();
 strA = str.split(‘ ‘);
 for(i=0;i<strA.length;i++) {
 capital = strA[i].charAt(0).toUpperCase();
 strA[i] = strA[i].replace(strA[i].charAt(0),capital);
 str = strA.join(‘ ‘);
 return str;

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

Like what you read? Give Muhammad Kamal a round of applause.

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