Skip to content

Instantly share code, notes, and snippets.

@cms
Last active May 10, 2019
Embed
What would you like to do?
capitalizeSentence
function capitalizeSentence(str) {
return str.replace(/^\w|(\s\w)/g, function(match, index) {
return match.toUpperCase()
});
}
capitalizeSentence('Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
// "Lorem Ipsum Dolor Sit Amet, Consectetur Adipiscing Elit."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment