Liam
0
Q:

javascript convert to title case

function titleCase(str) {
    return str
        .split(' ')
        .map((word) => word[0].toUpperCase() + word.slice(1).toLowerCase())
        .join(' ');
}
console.log(titleCase("I'm a little tea pot")); // I'm A Little tea Pot
2
function convertToTitleCase(str) {
    return str.replace( /wS*/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
}
var sentence=convertToTitleCase("we took a short walk.");//"We Took A Short Walk."
-2

New to Communities?

Join the community