How to capitalize strings in JavaScript?

0
671

JavaScript has different functions for different capitalization needs. You can use the following formulas for uppercasing and lowercasing a string as well as capitalizing only the first letter of a string.

var str = ‘This sentence needs SOME capitalization help.’;

// returns ‘this sentence needs some capitalization help.’
var lower = str.toLowerCase();

// returns ‘THIS SENTENCE NEEDS SOME CAPITALIZATION HELP.’
var upper = str.toUpperCase();

// returns ‘This sentence needs some capitalization help.’
var firstLetter = str.charAt(0).toUpperCase() + str.slice(1);

For capitalizing only the first letter of a string, you can also use the following function:

function uppercaseFirstLetter(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}

If you want to capitalize more than just strings in JavaScript, you can try our free title capitalization tool.


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