FOR EACH gives you access to the element in the array. FOR gives you access to the index of the array.
var elements:Array = [{name:'Orange'}, {name:'Apple'},{name:'Banana'},{name:'Pear'}]; for(var i:Object in elements) { trace("index: " + i); } for each(var e:Object in elements) { trace("element: " + e.name); }
The output from FOR loop looks like this:
index: 0 index: 1 index: 2 index: 3
The output from FOR EACH looks like this:
element: Orange element: Apple element: Banana element: Pear
Hopefully this helps someone from blunt force trauma caused by baning your head against the desk. Probably common knowledge for most, but it never hurts to post it.
its actually 'for in' vs 'for each'. 'for' looks like:
ReplyDeletefor (var d:int=0;d<6;d++)
{
trace("index: " + d);
}
Good point. I'll update the name.
ReplyDeleteI would like to say that i found this to be very useful, thank you!
ReplyDeleteuseful, thanx!
ReplyDeleteVery Useful
ReplyDelete