Last Updated : 20 Oct, 2023
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:
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:
'geeks_for_geeks'
'geeks_for_geeks'
'geeks_for_geeks'
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'
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4