Skip to content

Latest commit

 

History

History
18 lines (12 loc) · 761 Bytes

how_to_convert_string_to_title_case_with_javascript.md

File metadata and controls

18 lines (12 loc) · 761 Bytes

How to convert string to title case with JavaScript?

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