Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

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

How do I make the first character of a string uppercase if it's a letter, but not change the case of any of the other letters?

For example:

  • "this is a test""This is a test"
  • "the Eiffel Tower""The Eiffel Tower"
  • "/index.html""/index.html"

Answer*

Draft saved
Draft discarded
Cancel
3
  • Using /^[a-z]/i will be better than using . as the prior one will not try to replace any character other than alphabets Commented Jul 6, 2019 at 5:56
  • 11
    @CodeManiac there are so many languages and letters except [a-z] Commented Sep 11, 2021 at 23:20
  • This is nice to avoid having to declare a string variable (that most other answers assume there is). For example: const date = new Date("2024年08月12日").toLocaleDateString("fr-FR", { weekday: "long", year: "numeric", month: "long", day: "numeric" }).replace(/^./, str => str.toUpperCase());. Using the string concatenation solution would require putting the locale date string in a variable first (or worse, repeating the full date method). Commented Aug 12, 2024 at 10:52

lang-js

AltStyle によって変換されたページ (->オリジナル) /