Share on Google+Share on Google+

Get Length of Array

In this Tutorial we want to describe you a example code that helps in get a length of array.

Get Length of Array


In this Tutorial we want to describe you a example code that helps in  get a length of array. For this we are using JavaScript language. The code create a HTML Page specifying a string ,spilt character with their respective text field and a spilt button. On click a spilt button, a push function is invoked. This function include a variable array that instantiate an array object, and include the method string. split.

string. spilt( ) -  This method is used to break or spilt a string into a separate chunks. If we have a number like "1234568" and want to store each number separately, for this you need to specify the delimiter that enables you a break line after each number separately.

The splited string is stored in a  variable string. The for loop run and execute the script till the variable i is less than array length. Finally the doument.getElementBy Id print the element of string variable on the basis of respective ID.

javascript array split.html

  <title>Split Array</title>
    var array = new Array();
      function push(string,chr){
      var array= string.split(chr);
      var str = "<hr><b>Array :</b>"
      for(i=0;i<array.length;i++) {
      document.getElementById('myDiv').innerHTML = str;
   <h2>Split Array</h2>
    <form name="form1">
     <table width="407">
         <td width="154" align="right"><b>String</b></td>
         <td width="9"><b>&nbsp;:</b></td>
         <td width="224">
           <input type="text" name="string"/></td>
         <td width="154" align="right"><b>Split Character</b></td>
         <td width="9"><b>&nbsp;:</b></td>
         <td width="224">
           <input type="text" name="chr"/>
         <td width="154" align="right">&nbsp;</td>
         <td width="9">&nbsp;</td>
         <td width="224">
           <input type="button" Value=" Split " 
        <div id="myDiv"></div>


Download code



Posted on: November 13, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

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.

Discuss: Get Length of Array  

Post your Comment

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