17

Possible Duplicate:
Capitalize first letter of string in javascript

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

Community
  • 1
  • 1
David G
  • 94,763
  • 41
  • 167
  • 253

1 Answers1

39

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
meouw
  • 41,754
  • 10
  • 52
  • 69