[英]Get the “key” of an object in Actionscript-3
Given an Object: 给定一个对象:
myObj = {key : 'value'}
How do I get the key? 我如何获得钥匙?
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. 注意:
for(x in obj)
遍历键,而for each(x in obj)
迭代值。
Use a for in
loop 使用
for in
循环
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.