how to make the first letter of a word capital in javascript code example
Example 1: capitalize first letter javascript
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
console.log(capitalizeFirstLetter('foo bar bag')); // Foo
Example 2: javascript uppercase first character of each word
const uppercaseWords = str => str.replace(/^(.)|\s+(.)/g, c => c.toUpperCase());
// Example
uppercaseWords('hello world'); // 'Hello World'