function titleCase(str) {
let strWords=str.toLowerCase().split(" ");
for (let i=0;i<strWords.length;i++)
{
// strWords[i].split("");
strWords[i].replace(charAt(0),charAt(0).toUpperCase());
//strWords[i].join("");
}
str=strWords.join(' ');
return str;
}
titleCase("I'm a little tea pot");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36.
oh sorry I guess I missed out that last part, what my question was. I couldnt get it to work, cause first I tried doing the first letter capitalization by splitting each substring and capitalizing the first letter and then rejoining the substring to form the word. But the error I got was strWords[i].join is not a function. Those are the commented lines.
Then I used replace and I got it to work
I think this problem can be solved using regex too although Im not sure how
YUes, I did solve it by using the replace function to make the first letters uppercase, I was just trying to get a handle on different ways of solving the problem. Thanks for your input guys