How to capitalize the First Letter of Each Word in JavaScript?
I need to Create a function that takes a string as an argument and converts the first character of each word to uppercase. Return the newly formatted string.
1 Answer
This is a very easy question, you can try this function.
I used toUpperCase() function and some array function
function makeTitle(str) {
return str.split(' ')
.map(s => `${s.charAt(0).toUpperCase()}${s.slice(1)}`)
.join(' ')
}
Example
makeTitle('first title') // "First Title"
answer Link