Article

How to convert a string with hyphens to camelCase

Introduction

When you need to convert a string with hyphens to camelCase, it can seem daunting.

In this tutorial, we’ll take a look at how to create a simple utility function that converts strings with hyphens to camelCase using JavaScript.


function camelCase(str) {
  return str.replace(/-([a-z])/ig, function(all, letter) {
    return letter.toUpperCase();
  });
}


Conclusion

Converting strings to CamelCase can help you avoid potential confusion and make your text more organized. Additionally, converting CamelCase Strings to Text can help you save space and improve readability.

Article Stats

Real-time insights

1
min read
87
words
Apr 10, 2016
post

Share Article

Spread the knowledge

Quick Actions

Enjoying this?

Get more insights delivered to your inbox