How to create first letter of a string uppercase in JavaScript
In this tutorial, we will explain to you how to create the first letter of a string uppercase in JavaScript. here below the following example through we can easily convert capitalize first letter javascript.
Now in this article, we are using the toUpperCase(), slice(), and charAt() methods for javascript uppercase first letter in this example. so you can follow the below example for the first letter capital javascript.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | function capitalizeFirstLetter(string) { return string[0].toUpperCase() + string.slice(1); } console.log(capitalizeFirstLetter("hello")); //Hello function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); } console.log(capitalizeFirstLetter("world")); //World function capitalizeFirstLetter(string) { return string.replace(/^./, string[0].toUpperCase()); } console.log(capitalizeFirstLetter("apple")); //Apple |
Please follow and like us: