Anjan Dutta
Capitalize first letter of every word in Javascript
Capitalize first letter of every word in Javascript
To capitalize the first letter of every word in javascript you can use the below javascript code.
The Javascript
function capitalizeFirstLetter(str){ let stringArray = str.split(' ') let result = stringArray.map(function(word){ let cap = word[0].toUpperCase() return cap + [...word.slice(1)].join('') }) return result.join(' ') }
console.log(capitalizeFirstLetter('hello world'))
// > Hello World