How to capitalize first letter and lowercase the rest of the string

后端 未结 5 1227
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-20 05:22

I am trying to capitalize the first letter of only the first word in a sentence.

This is the data in the tsx file { this.text({ id: downloadPriceHistory

5条回答
  •  无人共我
    2021-01-20 06:06

    You only need to capitalize the first letter and concatenate that to the rest of the string converted to lowercase.

    function titleCase(string){
      return string[0].toUpperCase() + string.slice(1).toLowerCase();
    }
    console.log(titleCase('Download Price History'));

    This can also be accomplished with CSS by setting text-transform to lowercase for the entire element and using the ::first-letter pseudo element to set the text-transform to uppercase.

    .capitalize-first {
      text-transform: lowercase;
    }
    .capitalize-first::first-letter {
      text-transform: uppercase;
    }

    Download Price History

提交回复
热议问题