How to capitalize first character of a string in Javascript


Function ucfirst in Javascript

Method 1:

function ucfirst(string) {
  var uppercaseFirstLetter = string.charAt(0).toUpperCase();
  return uppercaseFirstLetter + string.slice(1);
}

Example:

alert(ucfirst('www.tutorialspots.com'))

Try it yourself

Leave a Reply