开发者

How do I make the first letter of a string uppercase? [duplicate]

开发者 https://www.devze.com 2023-03-03 12:10 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Capitalize first letter of string in javascript
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Capitalize first letter of string in javascript

How do I 开发者_如何学运维make the first letter of a string uppercase?


Here's a function that does it

function firstToUpperCase( str ) {
    return str.substr(0, 1).toUpperCase() + str.substr(1);
}

var str = 'hello, I\'m a string';
var uc_str = firstToUpperCase( str );

console.log( uc_str ); //Hello, I'm a string
0

精彩评论

暂无评论...
验证码 换一张
取 消