Created
March 21, 2016 18:07
-
-
Save Maslor/4db6f9cd36c6f85cbc00 to your computer and use it in GitHub Desktop.
capitalize all first letters of each word in string
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 titleCase(str) { | |
wordArray = []; | |
tempArray = []; | |
wordArray = str.toLowerCase().split(" "); | |
for (var i = 0; i<wordArray.length; i++){ | |
wordArray[i] = wordArray[i].split(""); | |
wordArray[i][0] = wordArray[i][0].toUpperCase(); | |
wordArray[i] = wordArray[i].join(""); | |
} | |
var finalString = wordArray.join(" "); | |
return finalString; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment