Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get value of associative array index 1

Status
Not open for further replies.

zinja

MIS
Nov 14, 2002
149
US
This is probably easy, but I have searched and cannot find the method to get the value of an index of an associative array element. In other words if I have an array:

myarray['Name1']=2;
myarray['Name2']=4;
myarray['Name3']=6;

How do I then get the 'Name1' later? I am using a loop to populate the array element names and values and need to be able to get the names later (in another function).

Thanks!,



LJ Wilson

My personal saying - Just remember, it can always get worse, and usually will.
 
[tt]for (var key in myarray) {
alert(key + " : " + myarray[key]);
}[/tt]
 
tsuji - Awesome! This has made a potentially large function very small!

Works great!

Thanks,


LJ Wilson

My personal saying - Just remember, it can always get worse, and usually will.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top