2017  Kodetalk | Feedback | Privacy Policy | Terms | About

To make the upper case of the first character of a string in JavaScript

I have a requirement like user can save any record with any format of text in database.

But when those details will display on the screen at that moment need to change the first character of the text.

e.g suppose user save the data like , kodetalk is a popular web site.

then it should show on the screen like, Kodetalk is a popular web site. by using javascript


Please find the code snippet,


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

console.log("kodetalk is a popular web site".capitalize());


Which will return and print "Kodetalk is a popular web site"

Answer is