Capitalize Words

Capitalizes the first letter of each word in a string, also known as title casing.

Contributed by @itsbrunodev

javascript
function capitalizeWords(str) {
  return str.replace(/\b\w/g, (char) => char.toUpperCase());
}
javascript
capitalizeWords("hello world"); // "Hello World"
GitHubEdit on GitHub