Home Java Javascript-array JavaScript array index of
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JavaScript array index of

Advertisement
In this Tutorial we want to describe that makes you to easy to understand 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

Advertisements

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: November 10, 2008

Related Tutorials

Ask Questions?    Discuss: JavaScript array index of   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Mark
March 17, 2013
This helped me

Good and easy tutorial. It helped me!
milind
May 2, 2012
code is not working

code is not working in IE indexOf method not supporttrd for arry in IE.
DMCA.com