How to title case the string in JavaScript
In this post we will give you information about How to title case the string in JavaScript. Hear we will give you detail about How to title case the string in JavaScriptAnd how to use it also give you demo for it if it is necessary.
JavaScript doesn’t offer any inbuilt methods to capitalize the first letter of the string.
Let’s write our function to convert the string to title case.
convert the string to lowerCase.
split the single string into an array of strings.
create an array.
loop through the array of strings and capitalize the first letter in every string.
return the title case string.
function titleCase(str){ str = str.toLowerCase().split(' '); let final = [ ]; for(let word of str){ final.push(word.charAt(0).toUpperCase()+ word.slice(1)); } return final.join(' ')}titleCase('this is a title case string');//"This Is A Title Case String"
There is another way to title Case the string by using the CSS.
.main{ text-transform:captialize;}
Happy coding…
Hope this code and post will helped you for implement How to title case the string in JavaScript. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs