Title Case Function in JS

Sunday, February 29 2020 1 min read

Ugh. It is still frustrating to capitalize first letter of each word in a string. Here’s a copy-paste function (ES6):

const titleCase = word => (
    word.charAt(0).toUpperCase() + word.slice(1)
)

const titleCaseSentence = str => (
  str.split(" ").map(word => titleCase(word)).join(" ")
)
Share