How to Get a String’s Length with Javascript


Learn how to get a string’s length with a very simple Javascript property: length. This is really useful when you want to do, for example, field validations with JS; you evaluate the length and then do something.

The property is called length. The usage is pretty straight forward: text.length

Lets say you have a variable sample that contains I love Arvixe!, the code to alert the length, would be:

var sample = “I love Arvixe!”;

alert(sample.length); //To alert it

Now lets say you want to alert a success message if the length is greater than 5:

if(sample.length > 5) {

That’s it! If you have any question, please let me know so I can assist you!

Best Regards,


Owner of Juapo2Services

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , , , | Posted under Programming/Coding | RSS 2.0

Author Spotlight

Richi González

I started programming when I was 12. I'm a Developer and have been working with the Clip-Bucket script since it came out. I'm the Liaison between Arvixe and Clip-Bucket, so anything you need regarding Clip-Bucket or any particular computer-related subject you need, let me know so I can assist you.

Leave a Reply

Your email address will not be published. Required fields are marked *