Skip to content

Instantly share code, notes, and snippets.

@mohsen1
Created August 12, 2012 07:55
Show Gist options
  • Select an option

  • Save mohsen1/3330593 to your computer and use it in GitHub Desktop.

Select an option

Save mohsen1/3330593 to your computer and use it in GitHub Desktop.
String.prototype.toCamelCase()
String.prototype.toCamelCase = function(){
return this.split(/\s+/).map(function(word, index){
word = word.toLowerCase();
if(index !== 0){
return word.split('').map(function(char, i){
if(i===0){
return char.toUpperCase();
}
return char;
}).join('')
}
return word;
}).join('');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment