Monday, November 18, 2024
Google search engine
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

Recent Comments