Another solution:
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
You could also add it to the String.prototype so you could chain it with other methods:
String.prototype.capitalizeFirstLetter = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
and use it like this:
'string'.capitalizeFirstLetter() // String






Leave a comment