Languages
[Edit]
EN

JavaScript - make first letter of string uppercase

5 points
Created by:
Root-ssh
178170

In this article, we would like to show you how to capitalize the first letter of a string in JavaScript.

Quick solution:

Note: presented below example is not universal. Read all article to find better universal solutions.

Output:

ES6 version

Edit

Output:

Note: read this article to capitalize text with CSS.

 

1. Capital letter of first-word examples

Edit

Presented approaches find the first letter in string and transform it into upper case. To find the beginning of the first world regular expression is used in the below examples.

1.1. String replace method with regular expression example

Edit

This section shows how to capitalize first-word occurrences with replace method.

Output:

1.2. String search method with regular expression example

Edit

This section shows how to capitalize first-word occurrences with search method.

Output:

Alternative titles

  1. How to uppercase first letter of string in JavaScript?
  2. How to capitalize first world of string in JavaScript?
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join