Answers for "how to capitalize first letter in word in Javascript"

98

javascript uppercase first letter

//capitalize only the first letter of the string. 
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}
//capitalize all words of a string. 
function capitalizeWords(string) {
    return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
Posted by: Guest on July-22-2019
1

js capitalize first letter

// this will only capitalize the first word
var name = prompt("What is your name");
firstLetterUpper = name.slice(0,1).toUpperCase();

alert("Hello " + firstLetterUpper + name.slice(1, name.length).toLowerCase());
Posted by: Guest on May-10-2021
0

capitalize first letter of string javascript

let val = '  this is test ';
val = val.trim();
val = val.charAt(0).toUpperCase() + val.slice(1);
console.log("Value => ", val);
Posted by: Guest on September-16-2021

Code answers related to "how to capitalize first letter in word in Javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language