Make the first letter of a string toUpperCase in JavaScript

Share:



How do I make the first letter of a string uppercase in JavaScript?
What is the best approach to capitalize words in a string?

  • Change all string to lowercase.
  • The regex matches the first letter of each word within the given string and transforms only that letter to uppercase.
  • \b matches a word boundary (the beginning or ending of word);
  • \w matches the following meta-character [a-zA-Z0-9].

Hi! I am Sartaj Husain. I am a Professional Software Developer, live in Delhi. I write blogs in my free time. I love to learn and share the knowledge with others because it is no good to try to stop knowledge from going forward. So free posts and tutorials. more..

No comments