Skip to content

Instantly share code, notes, and snippets.

@NEbere
Created February 11, 2016 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NEbere/248220d614a509730949 to your computer and use it in GitHub Desktop.
Save NEbere/248220d614a509730949 to your computer and use it in GitHub Desktop.
Return the provided string with the first letter of each word capitalized.
function titleCase(str) {
var strArray = str.toLowerCase().split(' ');
for (var i = 0; i < strArray.length; i++) {
strArray[i] = strArray[i][0].toUpperCase() + strArray[i].slice(1);
}
return strArray.join(' ');
}
titleCase("I'm a little tea pot");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment