Coding / Programming Videos

Post your favorite coding videos and share them with others!

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

In this tutorial, you’ll learn how to use JavaScript to capitalize the first letter of a sentence or an array of words.

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:
Find the largest number in an array JavaScript Tutorial:
How to find the longest word in a String with JavaScript:
How to reverse a String in JavaScript Tutorial:
Javascript String Length: How to determine the size of a string:
JavaScript join method: How to merge arrays into one value:
JavaScript How To Remove An Item From Array Tutorial:
Javascript How To Convert String To Number Tutorial:
JavaScript Create HTML Element: How to dynamically add tags to your pages:
JavaScript String Contains: How to check a string exists in another:
Link JavaScript to HTML: How to run your JavaScript code in the browser:
JavaScript Copy Array: How to make an exact copy of an array in JavaScript:
JavaScript Capitalize First Letter: How to make strings and arrays sentence case:
Javascript Print To Console Tutorial: Different ways to output data to the console:


Leave a Reply

Please Login to comment
Notify of
Translate »