searching through associative arrays

How do you search through an associative array

like myArray=new Array();
myArray[“cat”]=“mouse”
myArray[“dog”]=“frog”

can I search for either frog or cat somehow using a for loop?

Dan

You can use a regular for loop, yes. If your list is large, this might be slow after a while. You could use the .NET class library if you want to. There are great collection classes in System.Collections;

Good luck!

Could you provide a javascript example that will find
something in an associative array?

I’ll check out the collections but don’t really understand them very well since most don’t have javascript examples.
Dan

clerk=Array();
clerk["cat"]="meow";
clerk["dog"]="bark";
for(item in clerk){
	Debug.Log(clerk[item]);
}

This outputs
the word bark about 4 times.

I want it to ouptut
meow
bark

I didn’t know you could do this. I thought that would generate a compiler error. I would use Hashtable, Dictionary or something. Here is some info about what classes are available:
http://tutorial.visualstudioteamsystem.com/details.aspx?item=91

If you have used C++ before and like Templates, there is something in C# called Generics that handles the type conversions nicely. Then you should look into System.Collections.Generics.

EDIT: Here is another thread on the subject:
http://www.unifycommunity.com/wiki/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use%3F

Thanks for the references. I’m reading more about the different types.

It may be that only javascript is capable of this trick.

Dan