Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Javascript Javascriptexamples JavaScript substring length

Related Tutorials


Share on Google+Share on Google+

JavaScript substring length

This page discusses - JavaScript substring length

JavaScript substring length


This section illustrates you how to determine the length of substring in JavaScript.

You can see in the given example, we have defined a string and used the JavaScript method substring() in order to extract the substring from  the defined string. Now, we have used the JavaScript property length that allows to retrieve the length of the substring.

Here is the code:

<h2>Get the length of Substring</h2>
<script type="text/javascript">
var str = "Hello World";
var sub= str.substr(0,4);
document.writeln("The substring is :"+ sub+"<br>");
document.writeln("The length of the substring is :"+ sub.length);

Output will be displayed as:

Download Source Code:



If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Discuss: JavaScript substring length  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image