Capitalize first letter of every word in JavaScript
There are a number of ways to capitalize the first letter of the string in JavaScript. But this is my favorite and the easiest of them all.
const capitalizeFirstLetters = str => str.replace(/\b[a-z]/g, char => char.toUpperCase()); capitalizeFirstLetters('This is poop code!'); //Output will be 'This Is Poop Code!'