Lodash _.camelCase() Method
The _.camelCase() method is used to convert a string into a camel case string. The string can be space-separated, dash-separated, or can be separated by underscores.
Syntax:
_.camelCase(string)
Parameters: This method accepts a single parameter as mentioned above and described below:
- string: This parameter holds the string that needs to be converted into a camel case string.
Return Value: This method returns the camel case string.
Below example illustrate the Lodash _.camelCase() method in JavaScript:
Example 1:
Javascript
// Requiring the lodash library const _ = require( 'lodash' ); // Use of _.camelCase() method var str1 = _.camelCase( "Geeks for Geeks" ); // Printing the output console.log(str1); // Use of _.camelCase() method var str2 = _.camelCase( "GFG-Geeks" ); // Printing the output console.log(str2); |
Output:
geeksForGeeks gfgGeeks
Example 2:
Javascript
// Requiring the lodash library const _ = require( 'lodash' ); // Use of _.camelCase() method var str1 = _.camelCase( "Geeks__for__Geeks" ); // Printing the output console.log(str1); // Use of _.camelCase() method var str2 = _.camelCase( "GFG--Geeks" ); // Printing the output console.log(str2); |
Output:
geeksForGeeks gfgGeeks
Please Login to comment...