Skip to content

Instantly share code, notes, and snippets.

@timhobbs
Forked from johnsmith17th/camelCase.js
Created June 6, 2018 04:05
Show Gist options
  • Save timhobbs/23c891bfea312cf43f31395d2d6660b1 to your computer and use it in GitHub Desktop.
Save timhobbs/23c891bfea312cf43f31395d2d6660b1 to your computer and use it in GitHub Desktop.
To convert string to camel case in javascript.
function toCamelCase(string) {
string = string.toLowerCase().replace(/(?:(^.)|([-_\s]+.))/g, function(match) {
return match.charAt(match.length-1).toUpperCase();
});
return string.charAt(0).toLowerCase() + string.substring(1);
}
@Illizion
Copy link

this is golden :D Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment