Q:

Write a JavaScript program to capitalize the first letter of each word of a given string

0

Write a JavaScript program to capitalize the first letter of each word of a given string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function capital_letter(str) 
{
    str = str.split(" ");

    for (var i = 0, x = str.length; i < x; i++) {
        str[i] = str[i][0].toUpperCase() + str[i].substr(1);
    }

    return str.join(" ");
}

console.log(capital_letter("Write a JavaScript program to capitalize the first letter of each word of a given string."));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now