Home Java Javascript-array JavaScript Array Values



JavaScript Array Values
Posted on: November 13, 2008 at 12:00 AM
The Tutorial describes you a Array Values code in JavaScript. The Program create a HTML page specifying a button name 'Display Array Values'.

JavaScript Array Values

     

The Tutorial describes you a Array Values code in JavaScript. The Program create a HTML page specifying a button name 'Display Array Values'. An array variable instantiate an array object, that hold the element. On the click event of button, a function  display ( ) is  invoked that include a variable str. The str  hold the values of the array  object. The for loop execute and run the script till the value of variable i is less than array length.

The concatenated str and array are assigned to a variable str.

document.getElementById  - This return you the element on the basis of respective element Id.

On loading of this code, the browser displays you the value of element in str variable.

 

JavaScriptArrayValues.html

<html>
  <head>
  <title>JavaScript Array Values</title>
  <h1>JavaScript Array Values</h1>
  <hr></hr>
  <script>
  var array=new Array();
  array[0]="ROSE";
  array[1]="INDIA";
  array[2]=".NET";
  array[3]="ROHINI";
  </script>  
  <script>
  function display()
  {
  var str="<br>"+"<b>"+"Array holds the 
  following values: "
+"</b>";
  for(i=0;i<array.length;i++){
  str=str+"<br>"+array[i];
  }
  document.getElementById('myDiv').innerHTML= str;
  }
  </script>
  </head>
  <body>
  <input type="button"
 value="Display Array Values"
 name="button1"
 onClick="display()"/>
  <div id ="myDiv"></div>  
  </body>
</html>

Output of the program

Download Source code

Related Tags for JavaScript Array Values:
javajavascripthtmlcooparrayantfunctionscriptobjectbuttonfuneventioincludevariableloopdisplayippageclickexectutorialvaluenameclirialengthelementinvokeexeoocreateifforexecuteuncprogramvaluestoramrunldcieildeslisplvarpeinmlasstamntplaytrlessjispclesspecemfuncagemeobjprocutdescribetorsxespessatoldkinchtmisinstantinstantiatehallrayeaandarcodcodestrvatttutorscrssriripthavbesstabablantialuhatdispjeplprndodeonogrolo


More Tutorials from this section

Ask Questions?    Discuss: JavaScript Array Values   View All Comments

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.