Skip to content

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!'
See also  String building/concatenation in JavaScript

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.