Created
August 29, 2019 02:19
-
-
Save adamcrampton/a13387077f9c9bf7c9feefeb6f143776 to your computer and use it in GitHub Desktop.
Convert JavsScript string to Title Case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toTitleCase(string) { | |
return string.replace( | |
/\w\S*/g, | |
function(text) { | |
return text.charAt(0).toUpperCase() + text.substr(1).toLowerCase(); | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment