//for ..in 循环中的迭代变量包含属性所保存的值和名称 //for each..in 循环中的迭代变量只包含属性所保存的值,而不包含属性的名称 //对象遍历,可以获取属性名称 private function testObject():void { var myObj:Object = {x:20, y:30}; //i:属性名称 for (var i:String in myObj) { lab1.text+=i + ": " + myObj[i]+","; } var myObj:Object = {x:20, y:30}; for each (var num in myObj) { lab11.text+=num+","; } } //数组遍历,获取不到属性名称 private function testArray():void { //myArray[i]是对象,只能这样访问:myArray[i].x var myArray:Array = [{x:20},{x:30}]; //i:数组的序号 for (var i:String in myArray) { lab2.text+=i + ": " + myArray[i].x+","; } //item 是对象,只能这样访问:item.x var myArray:Array = [{x:20},{x:30}]; for each (var item in myArray) { lab22.text+=item.x+","; } }