Skip to content

Instantly share code, notes, and snippets.

@cschlyter
Created November 21, 2013 16:29
Show Gist options
  • Save cschlyter/7584973 to your computer and use it in GitHub Desktop.
Save cschlyter/7584973 to your computer and use it in GitHub Desktop.
Convert string to title case. input: fuel output: Fuel
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment