Posted on Arjun

How To Capitalize The First Letter Of A String In JavaScript

Here is the quick JavaScript code snippet to capitalize the first letter of a string.

How to use

Details of each function which we used to capitalize the first letter of a given string.
charAt() return the character at a certain index of a string. Here string.charAt(0) means selecting first character.

toUpperCase() function convert the string to uppercase letters. Here string.charAt(0).toUpperCase() means select the first character and convert it to uppercase

slice() function return the selected elements from an array. Here string.slice(1) will allow us to get the rest of the string and remove the first letter.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.
DMCA.com Protection Status