Skip to content

Instantly share code, notes, and snippets.

@johnhutchins
Created September 18, 2019 13:53
Show Gist options
  • Save johnhutchins/734502403565a9fd5e1d9f6e8d0ff188 to your computer and use it in GitHub Desktop.
Save johnhutchins/734502403565a9fd5e1d9f6e8d0ff188 to your computer and use it in GitHub Desktop.
uppercase first letter of each word in a string
function titleCase(str) {
//split to array of words
let wordArr = str.split(' ');
let newArr = [];
wordArr.forEach(function(e){
e = e.toLowerCase();
e = e.replace(e[0], e[0].toUpperCase());
newArr.push(e);
})
newArr = newArr.join(' ');
console.log(newArr);
return newArr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment