How to useLodash’s _.startCase in Javascript
Int his approach we use Lodash’s _.startCase method. This method converts the string to title case, which capitalizes the first letter of each word and converts the rest of the letters to lowercase.
Example: In this example we imports Lodash, defines a function toTitleCase that uses _.startCase to convert a string to title case, and prints “Welcome To Geeks For Geeks” to the console.
// Import the Lodash library
const _ = require('lodash');
function toTitleCase(str) {
return _.startCase(str);
}
console.log(toTitleCase("welcome to geeks for geeks"));
Output:
Welcome To Geeks For Geeks
Convert string to title case in JavaScript
Converting string to title case means converting to uppercase the first letter of every word in a sentence while the other ones remain in lowercase. In this article, we will see how to convert string to title case in JavaScript
Below are the approaches to convert string to title case in JavaScript:
Table of Content
- Using replace() function
- Using For loop to titlecase a string
- Using map() method
- Using reduce() method
- Using Foreach loop
- Using Regular Expressions and String Split
- Using Lodash’s _.startCase
Contact Us