loading...

JavaScript Capitalize first letter uppercase, lowercase and camel case

pakainfocom profile image pakainfo ・2 min read

Here is a quick javascript capitalize first letter code try it for the pure JavaScript version of ucfirst. This code try it will allow you to capitalize the first letter uppercase of a string using JavaScript.

javascript capitalize first letter

One of the most common operations(javascript capitalize first letter) with strings is to make the string capitalized: uppercase its first letter, and leave the rest of the string as-is.

I have learn to 4 ways to capitalize the first letter of A string in pure JS. Bellow Example Like as The built-in functions for Capitalize, uppercase, lowercase and camel case in JavaScript.

  • toUpperCase():
  • slice():
  • charAt():
  • replace():

How to make first letter of a string uppercase in JavaScript ?

uppercase first letter javascript


function capitalizeFLetter(userStr) { return userStr.charAt(0).toUpperCase() + userStr.slice(1); }

This soure code snippet will use the JavaScript function charAt to get the character at a certain index.

var firstLetter = userStr.charAt(0);

After that I use the uppercase function in JavaScript to set this user strings to be in javascript first letter uppercase.

var uppercaseFirstLetter = userStr.charAt(0).toUpperCase();

Then I can included the lots of the user string on to this capital letter by using the js function slice() help for the capitalize first letter js which will allow us to get the easy way of the string as well as delete the first letter.

var stringWithoutFirstLetter = userStr.slice(1)

You can visit my Article with More Examples : click here

Posted on by:

pakainfocom profile

pakainfo

@pakainfocom

My name is Angular King. I'm a full-stack developer, entrepreneur and owner of Pakainfo. I live in India and I love to write

Discussion

pic
Editor guide
 

Thanks for the article.

 

With the same idea as yours, it can also be done like this:

return userStr[0].toUpperCase() + userStr.slice(1);