I am trying to create a function in which after toLowerCase() input, will then capitalize the first letter in each element of an array.
function title_case ( String ) {
var result = "";
var text = String.toLowerCase().split(" ");
for (var i = 0; i < text.length; i++) {
var c = text[i].charAt(0).toUpperCase();
result = result + c;
}
return result;
}
Input:
document.write( title_case( "a kitty PUrrs") );
The resulting output of the current code is AKP. I'm trying to figure out a way to delete lowercase character with charAt(1) and then join() for the output if possible. Am I on the right track? I know there are simpler methods, but I'm trying to learn something along these lines.
String
as the argument name - I mean, you can, but don't. .. the whole function is simplyconst title_case = s => s.toLowerCase().split(' ').map(w => w[0].toUpperCase() + w.slice(1)).join(' ')
– World