Last Updated: February 25, 2016
·
469
· tmaster

Capitalize strings in JavaScript.

String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
};

var myString = 'abc';
console.log(myString.capitalize()); // output is 'Abc'