Created
July 5, 2018 14:53
-
-
Save moxdev/e8a52d32f7a63cfcd25284efc606d24f to your computer and use it in GitHub Desktop.
Capitalize first letter of every word in a string in Javascript
This file contains hidden or 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
capitalizeString = str => { | |
str = str.toString(); | |
str = str.split(" "); | |
for (var i = 0, x = str.length; i < x; i++) { | |
str[i] = str[i][0].toUpperCase() + str[i].substr(1); | |
} | |
return str.join(" "); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment