Lodash _.kebabCase() Method
Lodash _.kebabCase() method is used to convert the given string into a kebab case string. kebabCase is the practice of writing identifiers using hyphens instead of spaces. The string can be space-separated, dash-separated, or can be separated by underscores.
Syntax:
_.kebabCase([string='']);
Parameters:
- string: This parameter holds the string that needs to convert into kebab case string.
Return Value:
This method returns the kebab-cased string.
Example 1: In this example, we are converting a given string into the kebab case using the _.kebabCase() method.
Javascript
const _ = require( 'lodash' );
let str1 = _.kebabCase( "GEEKS FOR GEEKS" );
console.log(str1);
let str2 = _.kebabCase( "GFG--Geeks" );
console.log(str2);
|
Output:
"geeks-for-geeks"
"gfg-geeks"
Example 2: In this example, we are converting a given string into the kebab case using the _.kebabCase() method.
Javascript
const _ = require( 'lodash' );
let str1 = _.kebabCase( "GEEKS__FOR__GEEKS" );
console.log(str1);
let str2 = _.kebabCase( "GEEKS-----FOR_____Geeks" );
console.log(str2);
let str3 = _.kebabCase( "geeks--FOR--geeks" );
console.log(str3);
|
Output:
"geeks-for-geeks"
"geeks-for-geeks"
"geeks-for-geeks"
Last Updated :
20 Oct, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...