Skip to content
Related Articles

Related Articles

Improve Article

Lodash _.kebabCase() Method

  • Last Updated : 07 Sep, 2020
Geek Week

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"

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!

My Personal Notes arrow_drop_up
Recommended Articles
Page :