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.