function titleCase(str) {
var splitStr = str.toLowerCase().split(' ');
for (var i = 0; i < splitStr.length; i++) {
// You do not need to check if i is larger than splitStr length, as your for does that for you
// Assign it back to the array
splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
}
// Directly return the joined string
return splitStr.join(' ');
}
I have already visited those links but they used lowercase() and many more elements which I haven’t learnt yet
So, it would be very much helpful for me if you could provide me with the simplest way to solve this problem
I don’t understand why do you want the easiest way out here?
Aren’t you here to learn? Learning means stepping out of your comfort zone.
You can try and go the hard route we are here to support for you. :3 post your code a 100 times if you need to. However you will have to make the 1st step yourself here.