How to traverse the flex dictionary

Standard

Hi Guys!

Sometimes we might need to go through all the values from a action script dictionary.

Here is very simple example.

var dictionary:Dictionary = new Dictionary();
dictionary["first_name"] = "Shubham";
dictionary["last_name"] = "Goyal";
dictionary["location"] = "India";

for (var key:Object in dictionary)
{
   trace(key); // first_name, last_name, location
   trace(dictionary[key]); // Shubham, Goyal, India
}

for in loop traverse the whole dictionary and on each iteration we get key of the dictionary.

Cheers!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s