Saturday, November 22, 2025
HomeLanguagesJavascriptLodash _.capitalize() Method

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.

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:

"Geeksforneveropen"
"Gfg--neveropen"

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("neveropen--FOR--neveropen");
console.log(str3);


Output:

"Geeks__for__neveropen"
"Geeks for neveropen"
"Geeks--for--neveropen"
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS