How to use Lodash _.snakeCase() method In Javascript
Lodash _.snakeCase() method is used to convert the given string into a snake case string.
Example: below example uses _.snakeCase() method to convert a string to snake case.
const _ = require('lodash');
let myString = 'w3wiki';
let snakeCaseString = _.snakeCase(myString);
console.log(snakeCaseString);
Output:
geeks_for_geeks
How to convert a string to snake case using JavaScript ?
In this article, we are given a string in and the task is to write a JavaScript code to convert the given string into a snake case and print the modified string.
Examples:
Input: w3wiki
Output: geeks_for_geeks
Input: CamelCaseToSnakeCase
Output: camel_case_to_snake_case
There are some common approaches:
Table of Content
- Using match(), map(), join(), and toLowerCase()
- Using for loop
- Using Lodash _.snakeCase() method