Is there a simple way to convert a string to title case? E.g. john smith becomes John Smith. I\'m not looking for something complicated like John R
john smith
John Smith
Use /\S+/g to support diacritics:
/\S+/g
function toTitleCase(str) { return str.replace(/\S+/g, str => str.charAt(0).toUpperCase() + str.substr(1).toLowerCase()); } console.log(toTitleCase("a city named örebro")); // A City Named Örebro
However: "sunshine (yellow)" ⇒ "Sunshine (yellow)"