How do I make the first letter of a string uppercase in JavaScript

Format lowercase string to capitalize the beginning of each sentence.


function applySentenceCase(str) {
    return str.replace(/.+?[\.\?\!](\s|$)/g, function (txt) {
        return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
    });
}
DEMO
How do I make the first letter of a string uppercase in JavaScript How do I make the first letter of a string uppercase in JavaScript Reviewed by Bhaumik Patel on 7:09 PM Rating: 5