Skip to content

Instantly share code, notes, and snippets.

@youssman
Created November 5, 2014 11:25
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save youssman/16fcf30d8985d0f559f8 to your computer and use it in GitHub Desktop.
Save youssman/16fcf30d8985d0f559f8 to your computer and use it in GitHub Desktop.
Javascript convert dash (hyphen) to camelcase
function dashToCamelCase( myStr ) {
return myStr.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
}
var myStr = dashToCamelCase( 'this-string' );
alert( myStr ); // => thisString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment