javascript string first letter lowercase
// for lowercase on first letter
let s = "This is my string"
let lowerCaseFirst = s.charAt(0).toLowerCase() + s.slice(1)
javascript string first letter lowercase
// for lowercase on first letter
let s = "This is my string"
let lowerCaseFirst = s.charAt(0).toLowerCase() + s.slice(1)
how to capitalize first letter of word in javascript
function capitalizeFirstLetter(str, inAllWordsOfString = false) {
if (!inAllWordsOfString) {
//convert given string to lowercase
let lowerStr = str.toLowerCase();
// Now convert first character to upper case
let firstCharacter = str.charAt(0).toUpperCase();
// Now combine firstCharacter and lowerStr and return
return firstCharacter + lowerStr.slice(1);
} else {
let str1 = str.split(" ");
let returnStr = "";
for (let i = 0; i < str1.length; i++) {
let lowerStr = str1[i].toLowerCase();
returnStr =
returnStr + str1[i].charAt(0).toUpperCase() + lowerStr.slice(1) + " ";
}
return returnStr.trim();
}
}
capitalizeFirstLetter('hello word');
//output: Hello word
capitalizeFirstLetter('hello word', true);
//output : Hello Word
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us