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.
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: