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:
"neveropen-for-neveropen"
"gfg-neveropen"
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( "neveropen--FOR--neveropen" ); console.log(str3); |
Output:
"neveropen-for-neveropen"
"neveropen-for-neveropen"
"neveropen-for-neveropen"
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!