2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

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

userimage

Please find the code snippet,

<script>

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

window.onload=function(){
console.log("kodetalk is a popular web site".capitalize());
}

</script>

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

Answer is