Skip to content

Instantly share code, notes, and snippets.

@michael-lynch
Created September 12, 2022 21:10
Show Gist options
  • Save michael-lynch/ee93f4e26f34c8aa7a0975aea2e1c706 to your computer and use it in GitHub Desktop.
Save michael-lynch/ee93f4e26f34c8aa7a0975aea2e1c706 to your computer and use it in GitHub Desktop.
Capitalize each word in string
export const capitalize = sentence => {
const words = sentence.split(' ');
for (let i = 0; i < words.length; i++) {
if (words[i]) {
words[i] = words[i][0].toUpperCase() + words[i].substr(1).toLowerCase();
}
}
return words.join(' ');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment