JavaScript - Convert a string to spinal case



Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.



Solution Basic approach


function spinalCase(str) {
    return str
        .split(/\s|_|(?=[A-Z])/)
        .join('-')
        .toLowerCase()
}
console.log(spinalCase('ThisIsSpinalTap'));
console.log(spinalCase('This Is Spinal Tap'));
console.log(spinalCase('This_Is_Spinal_Tap'));

Output:


this-is-spinal-tap
this-is-spinal-tap
this-is-spinal-tap

Solution not working or have any suggestions? Please send an email to [email protected]



Join Our Facebook Group


Share this example


Download Android App

download android app

Popular javascript Examples









codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube