Title case a sentence?

后端 未结 13 1455
醉梦人生
醉梦人生 2021-02-10 01:27

I\'m trying to proper case a string in javascript - so far I have this code: This doesn\'t seem to capitalize the first letter, and I\'m also stuck on how to lowercase all the l

13条回答
  •  无人及你
    2021-02-10 01:52

    This should work. Notice how I set newstr[i] to the desired output. Functions like .toUpperCase() do not affect the original string. They only return a new string with the desired property.

    function titleCase(str) {
      var newstr = str.split(" ");
      for(i=0;i

提交回复
热议问题