Capitalize the first letter of a string using JavaScript

In this JavaScript article, we will show you how to capitalize the first letter of a string using JavaScript. There are many ways to uppercase the first letter of a string in JavaScript but we will look at two of them.

Methods to capitalize the first letter of a string

  1. Using charAt() and slice()
  2. Using regular expression

1. Using charAt() and slice()

In the first method, we will use the following functions and concat a string.

  • charAt() – This function returns the character at a given position in the string.
  • slice() – This function extracts a section of a string and returns it as a new string, without modifying the original string.

You can also use the following code.

2. Using regular expression

Let’s use the Regular Expression to make the first letter of a string in uppercase.

I hope you find this article helpful.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *