Friday, February 6, 2026
HomeLanguagesJavascriptLodash _.snakeCase() Method

Lodash _.snakeCase() Method

Lodash _.snakeCase() method is used to convert a string to a snake case. Snake case refers to combining words into a lowercase string with underscores(_) between words. The string can be space-separated, dash-separated, or can be separated by underscores.

Syntax:

_.snakeCase( [string=''] );

Parameters:

  • string parameter holds the string to convert.

Return Value:

This method returns the snake-cased string.

Example 1: In this example, we are converting a string into a snake-case using the _snakeCase() method by passing the string into the method.

Javascript




// Requiring the lodash library 
const _ = require("lodash");
 
// Use of _.snakeCase() method
console.log(_.snakeCase('Geeks For Geeks'));
console.log(_.snakeCase('GeeksForGeeks'));
console.log(_.snakeCase('@#$%GeeksForGeeks@#$%'));


Output:

'neveropen_for_neveropen'
'neveropen_for_neveropen'
'neveropen_for_neveropen'

Example 2: In this example, we are converting a string into a snake-case using the _snakeCase() method by passing the string into the method. while null is not holding any string so it is not printing anything in the console.

Javascript




// Requiring the lodash library 
const _ = require("lodash"); 
     
// Use of _.snakeCase() method
console.log(_.snakeCase(null));
console.log(_.snakeCase('123456789'));
console.log(_.snakeCase("gfg.Id"));


Output:

''
'123456789'
'gfg_id'
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32489 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11983 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12073 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7236 POSTS0 COMMENTS
Thapelo Manthata
6946 POSTS0 COMMENTS
Umr Jansen
6930 POSTS0 COMMENTS