filmov
tv
JavaScript Capitalize First Letter: How to make strings and arrays sentence case
Показать описание
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:
Комментарии