Open In App

Lodash _.capitalize() Method

Lodash _.capitalize() method is used to convert the first character of string to upper case and the remaining to lower case.  

Syntax:

_.capitalize([string=''..."])

Parameters:

This method accepts single parameter as mentioned above and described below:



Return Value:

This method returns the capitalize string.

Example 1: In this example, the Lodash _.capitalize() function is used to capitalize the first letter of the given strings.






const _ = require('lodash');
 
let str1 = _.capitalize("GEEKSFORGEEKS");
console.log(str1);
 
let str2 = _.capitalize("GFG--Geeks");
console.log(str2);

Output:

"Geeksforgeeks"
"Gfg--geeks"

Example 2: This code utilizes the Lodash _.capitalize() function to capitalize the first letter of each string in three different scenarios.




const _ = require('lodash');
 
let str1 = _.capitalize("GEEKS__FOR__GEEKS");
console.log(str1);
 
let str2 = _.capitalize("GEEKS FOR Geeks");
console.log(str2);
 
let str3 = _.capitalize("geeks--FOR--geeks");
console.log(str3);

Output:

"Geeks__for__geeks"
"Geeks for geeks"
"Geeks--for--geeks"
Article Tags :