文字列では、各単語は空間で区切られ、スペースの数は無制限です。
コードコピーは次のとおりです。
関数大文字(sting){
var words = string.split( "");
for(var i = 0; i <words.length; i ++){
words [i] = words [i] .charat(0).touppercase() + words [i] .slice(1);
}
return words.join( "");
}
var string = "ajax cookie event object";
Capitainize(string);
コードの重要な文に注意してください
コードコピーは次のとおりです。
words [i] = words [i] .charat(0).touppercase() + words [i] .slice(1);
単語[i] .charat(0).touppercase()は、文字列の最初の文字を取得し、元の文字列に変換しないため、元の文字列の他の文字と連結する必要があります。元の文字列に新しい値を割り当てます