views:

232

answers:

2

Given an Object:

myObj = {key : 'value'}

How do I get the key?

+5  A: 

You have to loop through the all the keys

for (var key:String in myObj) {
 //...
}
Patrick
wouldn't wouldn't key = 'value'?
Derek Adair
What do you mean ?
Patrick
A: 

Use a for in loop

var myObject:Object = {key1:"value1",key2:"value2"}

for (var s:String in myObject){
  trace("key:",s,"value:",myObject[s]);
}

output:

key: key1 value: value1
key: key2 value: value2
Reuben