How do I make the first letter of a string uppercase in JavaScript?

前端 未结 30 2196
南方客
南方客 2020-11-21 05:00

How do I make the first letter of a string uppercase, but not change the case of any of the other letters?

For example:

  • \"this is a test\"
30条回答
  •  北海茫月
    2020-11-21 05:30

    You can do it in one line like this

    string[0].toUpperCase() + string.substring(1)
    

提交回复
热议问题