Poor man's capitalization in JavaScript

I wanted to have simple capitalization in JavaScript (the first letter of the string should be upper-case, the rest of the string unchanged). Although the String object provides uppercase and lowercase functions, there is no capitalization function. The simplest expression I could come up with is this:
txt.substr(0,1).toUpperCase()+txt.substr(1)
Do you have a better solution?

No comments:

Post a Comment