Created
September 18, 2019 13:53
-
-
Save johnhutchins/734502403565a9fd5e1d9f6e8d0ff188 to your computer and use it in GitHub Desktop.
uppercase first letter of each word in a string
This file contains hidden or 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) { | |
//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