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

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.


Save Time With Our WordPress Plugin

Capitalize all of your headings at once in WordPress with our plugin.

  • Capitalize all titles and headings at once
  • Use keyboard shortcuts for title case and sentence case
  • Choose different styles for different headings

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