写法一:

let name = 'hello'
name.charAt(0).toUpperCase() + name.slice(1)

写法二:

let name = 'hello'
name.slice(0, 1).toUpperCase() + name.slice(1)

写法三:

let name = 'hello'
name.substring(0, 1).toUpperCase() + name.substring(1)

三种写法的原理都是一样的,提取首字母转为大写,和剩余的字符一起组成一个新的字符

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2021-12-18
  • 2021-08-31
  • 2021-10-21
  • 2021-08-09
相关资源
相似解决方案