Reputation: 21915
Given an Object:
myObj = {key : 'value'}
How do I get the key?
Upvotes: 23
Views: 24820
Reputation: 15717
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.
Upvotes: 38
Reputation: 1202
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
Upvotes: 11