Skip to content

Instantly share code, notes, and snippets.

@Maslor
Created March 21, 2016 18:07
Show Gist options
  • Save Maslor/4db6f9cd36c6f85cbc00 to your computer and use it in GitHub Desktop.
Save Maslor/4db6f9cd36c6f85cbc00 to your computer and use it in GitHub Desktop.
capitalize all first letters of each word in string
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