Home Java Javascript-array JavaScript Array get key

Related Tutorials


 
 

Share on Google+Share on Google+

JavaScript Array get key

Advertisement
In this Tutorial we want to describe you a code that help you in understanding JavaScript Array get key.

JavaScript Array get key

     

In this Tutorial we want to describe you a code that help you in understanding JavaScript Array get key. For this we implement JavaScript as Scripting language. We have taken an array that creates and initializes an associative array including different three elements. The elements in this array  are addressed using the key strings("R", "I", and "N") instead of an array element number (0, 1, or 2). In the example given below ,array["R"] returns you "ROSE". This provides you to create and use arrays with more different addresses schemas.. The given below code uses for loop to iterate this array..

 

 

 

 

JavaScript_Array_get_key.html

<html>
  <head>
  <h1>JavaScript Array get key</h1>  
  <title>JavaScript Array get key</title>
  </head>
  <body>
  <script language="javascript" type="text/javascript">
  array = {"R" "ROSE""I" "INDIA",".N":".NET" };
  for (key in array)
  document.write("For the Element " "<b>"+array[key]+"</b>" 
  " Key value is  " +"<b>"+key+"</b>"+"<br>");  
  </script>
  
  </body>
</html>

Output of the program

Download Source code

Advertisement

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

Discuss: JavaScript Array get key   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
LJay
April 24, 2012
Wrong

First of all, what you're defining is not an array its an object and you're iterating all properties in the object here. An array would be defined as "var arr = ['rose','stuff'];", also if you try to define an array value by using "arr['rose'] = 'red';" you're adding a property to the "arr" object, you could replace this code also by writing "arr.rose = 'red';" JavaScript has no associative arrays as you might know them from C# or Java Hashmaps.
Pankaj
July 10, 2012
Thanks

that was of help! :)
DMCA.com