Skip to content

Instantly share code, notes, and snippets.

@basekays
Created November 3, 2016 02:01
Show Gist options
  • Select an option

  • Save basekays/a85636535186c39f4be405d204447067 to your computer and use it in GitHub Desktop.

Select an option

Save basekays/a85636535186c39f4be405d204447067 to your computer and use it in GitHub Desktop.
take a string, change the first character of each word into capitalized letter :)
function titleCase(str) {
var strLowerCase = str.toLowerCase();
var split = strLowerCase.split(" ");
for (var i = 0; i< split.length; i++) {
var firstChar = split[i].charAt(0).toUpperCase();
split[i] = firstChar + split[i].substr(1);
}
var newStr = split.join(" ");
return newStr;
}
titleCase("fOrce aWAKENS");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment