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

Опубликовано: 17 Январь 2019
на канале: Code With Bubb
27,467
369

In this tutorial, you’ll learn how to use JavaScript to capitalize the first letter of a sentence or an array of words. Get my free 32 page eBook of JavaScript HowTos 👉https://bit.ly/2ThXPL3

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:

JavaScript How To Remove An Item From Array Tutorial:    • JavaScript How To Remove An Item From...  
Javascript String Length: How to determine the size of a string:    • Javascript String Length: How to dete...  
How to find the longest word in a String with JavaScript:    • How to find the longest word in a Str...  
Find the largest number in an array JavaScript Tutorial:    • Find the largest number in an array J...  
Check if a String is a palindrome with JavaScript Tutorial:    • Check if a String is a palindrome wit...  
How to reverse a String in JavaScript Tutorial:    • How to reverse a String in JavaScript...  
JavaScript join method: How to merge arrays into one value:    • JavaScript join method: How to merge ...  
Javascript How To Convert String To Number Tutorial:    • Javascript How To Convert String To N...  
JavaScript Create HTML Element: How to dynamically add tags to your pages:    • JavaScript Create HTML Element: How t...  
JavaScript String Contains: How to check a string exists in another:    • JavaScript String Contains: How to ch...  
Link JavaScript to HTML: How to run your JavaScript code in the browser:    • Link JavaScript to HTML: How to run y...  
JavaScript Copy Array: How to make an exact copy of an array in JavaScript:    • JavaScript Copy Array: How to make an...  
Javascript Print To Console Tutorial: Different ways to output data to the console:    • Javascript Print To Console Tutorial:...   Channel Handle @codebubb


Смотрите видео JavaScript Capitalize First Letter: How to make strings and arrays sentence case онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Code With Bubb 17 Январь 2019, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 27,467 раз и оно понравилось 369 людям.