0 votes
in JavaScript by
How to convert string to title case with javascript?

1 Answer

0 votes
by

Title case means that the first letter of each word is capitalized. You can convert a string to title case using the below function,

function toTitleCase(str) {
  return str.replace(/\w\S*/g, function (txt) {
    return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
  });
}
toTitleCase("good morning john"); // Good Morning John

Related questions

0 votes
asked Oct 4, 2023 in JavaScript by GeorgeBell
0 votes
asked Oct 21, 2023 in JavaScript by DavidAnderson
...