Coding / Programming Videos

Post your favorite coding videos and share them with others!

Javascript String Length: How to determine the size of a string

In this tutorial, we’ll take a look at the JavaScript String Length property and how you can use this to determine the size of a string.

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

It’s a very common thing to do but to use the JavaScript string length property is luckily really simple.

In the tutorial, you’ll learn how to use the .length property to find out the length of a string but we’ll also look at some common scenarios that you might want to use the length property for.

Checking for null / falsy JavaScript string lengths – This is something that is quite common, you might have an array of strings that you want to check whether or not they are empty i.e. remove any blank strings from an array. Whilst a blank string is considered falsy, you might want to check the additional length property to make your code a bit more readable (or if you have a specific case to allow null or undefined values).

Checking variables with a JavaScript string length comparison – If you have two strings that you want to compare the length of then you’ll need compare their lengths by accessing the length property of both variables.

The Javascript string length undefined Problem – If you get an undefined result when trying to get a string’s length in JavaScript then chances are you don’t actually have a string. In the tutorial i’ll talk you through how to check that you’re actually working with a string and to convert it to one if necessary.

Javascript String Length Validation on Input fields – The final example we’ll look at is how to validate an input field’s length with JavaScript by checking the length property of the string entered into the input box.

Other videos in the JavaScript Snippets series:
Find the largest number in an array JavaScript Tutorial: https://youtu.be/fOFSmCjvcFY
How to find the longest word in a String with JavaScript: https://youtu.be/j9cAav7VIv4
How to reverse a String in JavaScript Tutorial: https://youtu.be/k7zzWvQaEhc
Javascript String Length: How to determine the size of a string: https://youtu.be/OO0_9gq8NNI
JavaScript join method: How to merge arrays into one value: https://youtu.be/90MVWda5DlM
JavaScript How To Remove An Item From Array Tutorial: https://youtu.be/UvohHcj9I-s
Javascript How To Convert String To Number Tutorial: https://youtu.be/K-Twvsg3K_M
JavaScript Create HTML Element: How to dynamically add tags to your pages: https://youtu.be/VsXCK_2DJzA
JavaScript String Contains: How to check a string exists in another: https://youtu.be/uLT9iPccVZs
Link JavaScript to HTML: How to run your JavaScript code in the browser: https://youtu.be/821C5aJ3SLM
JavaScript Copy Array: How to make an exact copy of an array in JavaScript: https://youtu.be/5rybkWfeh-A
JavaScript Capitalize First Letter: How to make strings and arrays sentence case: https://youtu.be/8IEI-7fj2j4
Javascript Print To Console Tutorial: Different ways to output data to the console: https://youtu.be/pkFbigsR7jI

Bookmark(0)
 

Leave a Reply

Please Login to comment
  Subscribe  
Notify of
Translate »