Capitalize every word

OSCC · JavaScript, String, Regexp · Oct 22, 2020

Capitalizes the first letter of every word in a string.

const capitalizeEveryWord = str =>
  str.replace(/\b[a-z]/g, char => char.toUpperCase());
capitalizeEveryWord('hello world!'); // 'Hello World!'

Recommended snippets