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'.

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'.

JavaScript 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