Uppercase the first letter of a string in javascript

by Francis 2014-08-29 11:05:00

Method 1 : using regex
str.replace(/^[a-z]/, function(m){ return m.toUpperCase() });
Method 2 : using substr
str.substr(0, 1).toUpperCase() + str.substr(1);
Method 3 : using string chars as array
str[0].toUpperCase() +str.substring(1);
Method 4 : using .charAt(0)
str.charAt(0).toUpperCase() + str.substring(1);


 
740
like
0
dislike
0
mail
flag

You must LOGIN to add comments