Answers for "split a string in js and capitalize first letter of each word"

1

js split string on capital letter second

'ThisIsTheStringToSplit'.split(/(?=[A-Z])/); // positive lookahead to keep the capital letters
Posted by: Guest on January-27-2021
4

javascript capitalize first letter of each word

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(' '); 
}

document.write(titleCase("I'm a little tea pot"));
Posted by: Guest on May-01-2020

Code answers related to "split a string in js and capitalize first letter of each word"

Code answers related to "Javascript"

Browse Popular Code Answers by Language