In JavaScript, we can use the toLowerCase
method to convert a string into a lowercase string. The toLowerCase
method will return a new string.
var str = "UPPER Case";var lowerCaseStr = str.toLowerCase();console.log(lowerCaseStr);
In JavaScript, we can also use the toUpperCase
method to convert a string into an uppercase string. The toUpperCase
method will return a new string.
var str = "uppercase";var upperCaseStr = str.toUpperCase();console.log(upperCaseStr);
We don’t have any in-build method to capitalize a string. However, we can implement our own method. The steps to capitalize a string are:
function capitalize(str) {const lowerCaseString = str.toLowerCase(), // convert string to lower casefirstLetter = str.charAt(0).toUpperCase(), // upper case the first characterstrWithoutFirstChar = lowerCaseString.slice(1); // remove first character from lower case stringreturn firstLetter + strWithoutFirstChar;}console.log(capitalize("javaScript"));console.log(capitalize("educative.io"));