Flex中的 for in 与 for each in

时间:2021-05-08 04:03:13
 

for...in循环中的迭代变量是对象中的键名(Flex中叫属性?)

var mockData:Object={ID: 1,Say:"Hello",Name:"yuxuanji"};


for (var entry:Object in mockData)
{
trace(entry);
}

console output:

ID
Say
Name

//结论:for 遍历的是key
for each...in循环中的迭代变量是对象键值对中保存的值(属性所保存的值)

for each (var entry:Object in mockData)

{
trace(entry);

}

console output:

123
Hello

yuxuanji

//结论:for each遍历的是value