Home Java Javascript-array JavaScript array index of



JavaScript array index of
Posted on: April 17, 2011 at 12:00 AM
javascript array index of

JavaScript array index of 

In this Tutorial we want to describe that makes you to easy to understand JavaScript array index of. We are using JavaScript as scripting language. An array var instantiate array object that hold the values of an elements. The document. write print the Element in the array are followed by break line. The for loop execute the script till variable  i is less than the length of an array. The document. write print the value of element that an array object hold specified by [0]-[3] array indexing followed by break line.

1)index of( )  - This return the position of the value that is hold by an array object and store in a variable index.

Finally the document. write print the index position of India on array.

JavaScript_array_indexof.html

<html>
  <head><h1>JavaScript Array indexof </h1>
  <title>JavaScript array indexof </title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
  <script language="javascript" type="text/javascript">
  var array=new Array();
  array[0]="Rose";
  array[1]="India";
  array[2]=".net";
  array[3]="Rohini";
  document.write("<b>"+"Element in the array are "+"</b>""<br />");
  document.write("=================""<br />");
  for(var i=0;i<array.length;i++){
  document.write(array[i]+"<br>")
  }
  document.write("=================""<br />");
  var index = array.indexOf("India");
  document.write("<b>"+"Index of India on the array is: "+"</b>"+index);
  </script> 
  </body>
</html>

Output of the program

Download Source code

Related Tags for JavaScript array index of:


More Tutorials from this section

Ask Questions?    Discuss: JavaScript array index of  

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.