[Résolu] Remplacer la casse kebab par la casse serpent (tirets avec underscore)

  

2
Début du sujet

I need to create a function in javascript which will replace

kebab case (dashes: "-")

avec

snake cased version (underscore dash "_")

in a string.

1 Réponse
2

Here you go (with replace and regex):

function kebabToSnake(str) {
    //replace all dashes with
    var myString = str.replace(/-/g, "_");
    //return str
    return myString;
    //try with: "this - is -a - ---test";
}
Partager :