How to Uppercase the First Letter of a String in JavaScript?

0
4818

To uppercase only the first letter in a string in JavaScript, you can use the following code:

var str = "Hello World!";
var newStr = str.charAt(0).toUpperCase() + str.slice(1);

The result will be:

"Hello world!"

To reuse this code multiple times, you can use the following function:
function uppercaseFirstLetter(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}

You can also capitalize the entire string or lowercase the whole string.


Capitalize My Title is a dynamic title capitalization tool used to make sure your titles or headlines use proper capitalization rules according to various style guides include APA, AP, MLA, and Chicago. It also counts your words and checks for grammar issues.

LEAVE A REPLY

Please enter your comment!
Please enter your name here