Skip to content
Related Articles

Related Articles

Lodash _.kebabCase() Method

Improve Article
Save Article
  • Last Updated : 07 Sep, 2020
Improve Article
Save Article

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, collection, strings, objects, numbers etc.

The _.kebabCase() method is used to convert the given string into kebab case string. kebabCase is the practice of writing identifiers using hyphens instead of spaces.

Syntax:

_.kebabCase([string=''])

Parameters: This method accepts single parameter as mentioned above and described below:

  • string: This parameter holds the string that need to convert into kebab case string.

Return Value: This method returns the kebab cased string.

Example 1:

Javascript




const _ = require('lodash'); 
  
var str1 = _.kebabCase("GEEKS FOR GEEKS");
console.log(str1);
  
var str2 = _.kebabCase("GFG--Geeks");
console.log(str2);


Output:

"geeks-for-geeks"
"gfg-geeks"

Example 2:

Javascript




const _ = require('lodash'); 
  
var str1 = _.kebabCase("GEEKS__FOR__GEEKS");
console.log(str1);
  
var str2 = _.kebabCase("GEEKS-----FOR_____Geeks");
console.log(str2);
  
var str3 = _.kebabCase("geeks--FOR--geeks");
console.log(str3);


Output:

"geeks-for-geeks"
"geeks-for-geeks"
"geeks-for-geeks"
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!