JavaScript Capitalize first letter uppercase, lowercase and camel case

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)

Putting this altogether I get the JavaScript soure code simple use a ucfirst() Best alternative Way Like below Example.

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

How To Capitalize The First Letter Of A String In JavaScript?

Imp Note: You Don’t forget that if you just want to your any User string like as a any article or post capitalize for main presentational intention on a Great create a Web Page, CSS design might be a good helpful functions, just included a capitalize user define class to your any webpages HTML paragraph as well as use: js capitalize first letter of string

p.capitalize {
  text-transform: capitalize;
}

Example 1: uses slice() method

   
   
      
        capitalize javascript - www.pakainfo.com 
      
        
       
    
        

Pakainfo

Example 2: uses slice() method

   
   
      
        javascript capitalize first letter of string	 
      
        
       
    
        

Pakainfo

Example 3: uses string.replace() method

   
   
      
        js capitalize first letter of string	      
      
        
       
    
        

Pakainfo

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about javascript capitalize first letter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment