JavaScript Capitalize First Letter: How to make strings and arrays sentence case

preview_player
Показать описание

Don’t forget to subscribe to the Junior Developer Central channel for more videos and tutorials!

You’ll also learn some tips and tricks on how to make this simple bit of code more powerful within your applications.

Although this may seem like a simple task, using JavaScript to capitalize the first letter of a string or using JavaScript to capitalize first letter of each word of a string, it’s a common task for Junior Developers to do.

It will mainly come in to play when working with presented data to the user as you want to ensure a consistent experience for the user. For example, it might be that data was stored (possibly by the user themselves) in all upper or lowercase.

So, How do you capitalize the first letter in HTML?

The first thing you need to do is to get the first character of the string using either bracket notation [] or the charAt function. In the video, i’ll explain the difference between the two.

Once you have the first character you can make this uppercase with the toUpperCase function which will transform the character to uppercase.

The final thing you’ll need to do is get the rest of the remaining original string and add it to the first, uppercase letter. You can do this with the slice function which ill show in the video.

Other videos in the JavaScript Snippets series:

Рекомендации по теме
Комментарии
Автор

Thank you! Wasn't difficult to follow and was exactly what I needed!

KodyAgue
Автор

Thanks so much. I am new to coding and your video has helped me find uppercase in arrays.

namirasyed
Автор

Thank you very much just what i needed very simple and easy to follow :)

JillYva
Автор

I was looking for this solution. Thank you so much

gopinathkrm
Автор

loved it, can you please also make a video to show how to make a copy to clickboard function

ShubhamSingh-egwq
Автор

Thanks! This video helped me so much!!

puanabidah
Автор

Hay JR Dev Central! Just discovered your channel trying to do a FCC challenge (I bet most can guess which one lol) it's nice to be able to learn from someone with a similar accent :)
do you do any in person courses or tutoring?

techslugz
Автор

Hi, could you please show how you would do this for an array with a for..of loop? Thanks

RavingAngel
Автор

what if the string starts with a number though?

kovoempire
Автор

How to convert 'dct academy' to 'DctAcademy'

mallireddydeepak
Автор

How can I get below output for given string ?
Given String =This is bird.it can fly.thank you.
Output = This IS BIRD.
It CAN FLY.
Thank YOU.
Please give me the code for it.

katyrihannah