Underscore.js _.toDash() Method

The _.toDash() method is used to convert a camel case string to a dashed string.

Syntax:

_.toDash( camelCaseString);

Parameters:

  • toDash: This method takes a camel Case String to convert.

Return Value: This method returns a converted dashed string.

Note: This will not work in normal JavaScript because it requires the underscore.js contrib library to be installed.



underscore.js contrib library can be installed using npm install underscore-contrib –save.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var dashst  = _.toDash("geeksForGeeks");
  
console.log("The converted Dashed String is :",dashst);

chevron_right


Output:

The converted Dashed String is : geeks-for-geeks

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var dashst  = _.toDash("aBC");
  
console.log("The converted Dashed String is :",dashst);

chevron_right


Output:

The converted Dashed String is : a-b-c

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.