Navigate back to the homepage

How to convert string to title case in typescript?

April 22nd, 2022 · 1 min read
keep affilitate

Hi Friends 👋,

Welcome to Infinitbility ❤️!

Today, we are going to learn how to convert string in any case like camel case, paskal case to title case in typescript, here we will create toTitleCase() custom method to convert string any case to title case.

Well, let’s create a function which return the provided string with the first letter of each word capitalized and Make sure the rest of the word is in lower case.

let’s dive in code…

2 * Convert string to title case
3 *
4 * @param str
5 * @returns title case string
6 */
7const toTitleCase = (str: string) => {
8 return str.toLowerCase().split(' ').map(function(word) {
9 return word.replace(word[0], word[0].toUpperCase());
10 }).join(' ');
13toTitleCase(`I'm a infinitbility`);

Well, when you run above code, you can able to see above string converted in the title case.

For now, let’s check output.


TypeScript, convert string to title case example
TypeScript, convert string to title case example

All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

melio affilitate

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide



More articles from Infinitbility

How to convert comma separated string to array in typescript?

TypeScript, convert comma (,) separated string to array example.

April 20th, 2022 · 1 min read

How to convert a string to uppercase in typescript?

TypeScript, convert a string case to uppercase example.

April 17th, 2022 · 1 min read
© 2020–2022 Infinitbility
Link to $ to $ to $ to $ to $ to $mailto:[email protected]