Javascript Make the First Letter of a String in Uppercase
Learn how to Make the First Letter of a String in Uppercase Using Javascript
Published
-Javascript Make the First Letter of a String in Uppercase -First Letter into Uppercase Using Object Oriented -Other ways to Make First Letter in UpperCase
Javascript Make the First Letter of a String in Uppercase
Here are some approaches to convert the first letter of a string into uppercase using Javascript.
function capitalizeFirstLetter(string) {
return string[0].toUpperCase() + string.slice(1);
}
First Letter into Uppercase Using Object Oriented
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
"hello world".capitalize();
Other ways to Make First Letter in UpperCase:
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function capitalizeFirstLetter(string) {
return string.replace(/^./, string[0].toUpperCase());
}
String.prototype.capitalizeFirstLetter = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}