You can convert a string to title case by splitting the string into words, capitalizing the first letter of each word, and then joining them back together.
Example:
function toTitleCase(str) {
return str.replace(/\b(\w)/g, char => char.toUpperCase());
}
console.log(toTitleCase('hello world')); // 'Hello World'
Tags: basic, JavaScript, string manipulation
URL: https://www.tiktok.com/@jsmentoring/photo/7457578972889615648