How to Get a String’s Length with Javascript

Hello,

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) {
 alert("Success");
}

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

Best Regards,

Richi

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

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 became a Liaison between Arvixe and Clip-Bucket, so I am here to assist you with anything you need regarding Clip-Bucket or any particular computer-related subject you need. Best Regards, Richi

Leave a Reply

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


7 + 5 =

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>