Lodash _.toDash() Method
Last Updated :
13 Nov, 2023
Lodash _.toDash() method is used to convert a camel case string to a dashed string.
Syntax:
_.toDash( camelCaseString);
Parameters:
This method takes one parameter as mentioned above and described below:
- camelCaseString: This method takes a camel Case String to convert into dashed string.
Return Value:
This method returns a converted dashed string.
Note: This will not work in normal JavaScript because it requires the lodash.js contrib library to be installed. Lodash.js contrib library can be installed using npm install lodash-contrib.
Example 1: In this example, the code utilizes the _.toDash
method from the Lodash-contrib library to convert a camelCase string into a dashed string and displays the converted result in the console.
Javascript
let _ = require( 'lodash-contrib' );
let dashst = _.toDash( "geeksForGeeks" );
console.log( "The converted Dashed String is :" , dashst);
|
Output:
The converted Dashed String is : geeks-for-geeks
Example 2: In this example, the code defines a variable using the Lodash-contrib library and employs the _.toDash
method to convert a string from camelCase to a dashed format, displaying the converted result in the console.
Javascript
let _ = require( 'lodash-contrib' );
let dashst = _.toDash( "aBC" );
console.log( "The converted Dashed String is :" , dashst);
|
Output:
The converted Dashed String is : a-b-c
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...