I am working through some problems on CoderByte. The goal of this function is to take a string and capitalize the first letter of each word. For example, 'hello world'
to 'Hello World'
. I can't figure out why this code gives me 'hello world'
and not 'Hello World'
. I know this line array[i][0] = array[i][0].toUpperCase();
is the problem, but don't understand why it isn't working. I came up with an alternative solution but I am wondering why this didn't work. Thanks so much for your help!
function LetterCapitalize(str) {
var array = str.split(' ');
for (var i = 0; i < array.length; i++) {
array[i][0] = array[i][0].toUpperCase();
}
return array.join('');
}
LetterCapitalize('hello world');