To capitalize the first letter in a string is easy if you undertake some steps.
First of all you should get the first letter of the string by setting the charAt() method at 0 index:
Next, you should make the first letter uppercase with the toUpperCase() method:
Then, you should get the remainder of the string with the help of the slice() method.
The final step you should take is creating a function accepting a string as only argument and returns the concatenation of the first capitalized letter and the remainder of the string:
You may also add that function to the String.prototype to use it directly on a string:
The toUpperCase() method returns the string value that is converted to uppercase. It does not affect any special character, digits, and alphabets already in uppercase.