Answers for "uppercase word method in javascript"

1

uppercase in word javascript

function toTitleCase(str) {
    return str.replace(/\w\S*/g, function(txt){
        return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
    });
}
Posted by: Guest on April-11-2020
30

javascript capitalize words

//Updated 
//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 December-12-2020

Code answers related to "uppercase word method in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language