MST
星途 面试题库

面试题:TypeScript中string类型如何实现首字母大写

在TypeScript中,给定一个字符串变量,例如`let str = 'hello world';`,请编写代码将其首字母大写,要求使用string类型的相关方法来实现。
17.2万 热度难度
前端开发TypeScript

知识考点

AI 面试

面试题答案

一键面试
let str = 'hello world';
let newStr = str.charAt(0).toUpperCase() + str.slice(1);
console.log(newStr);