Lodash _.capitalize() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.
The _.capitalize() method is used to convert the first character of string to upper case and the remaining to lower case.
Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!
Syntax:
_.capitalize([string=''])
Parameters: This method accepts single parameter as mentioned above and described below:
- string: This parameter holds the string that need to convert first character to upper case character and remaining to lower case characters.
Return Value: This method returns the capitalize string.
Example 1:
Javascript
const _ = require('lodash'); var str1 = _.capitalize("GEEKSFORGEEKS");console.log(str1); var str2 = _.capitalize("GFG--Geeks");console.log(str2); |
Output:
"Geeksforgeeks" "Gfg--geeks"
Example 2:
Javascript
const _ = require('lodash'); var str1 = _.capitalize("GEEKS__FOR__GEEKS");console.log(str1); var str2 = _.capitalize("GEEKS FOR Geeks");console.log(str2); var str3 = _.capitalize("geeks--FOR--geeks");console.log(str3); |
Output:
"Geeks__for__geeks" "Geeks for geeks" "Geeks--for--geeks"


