Get the "key" of an object in Actionscript-3

Derek Adair picture Derek Adair · Mar 11, 2010 · Viewed 24.1k times · Source

Given an Object:

myObj = {key : 'value'}

How do I get the key?

Answer

Patrick picture Patrick · Mar 11, 2010

You have to loop through the all the keys

for (var key:String in myObj) {
 //...
}

Note: for(x in obj) iterates over the keys, while for each(x in obj) iterates over the values.