Posted By

_mantra on 07/01/10


Tagged

actionscript as3


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

PixelJuice
davidino1978
alptugan
tspitzr
shockway


AS3 new for each loop


 / Published in: ActionScript 3
 

use AS3's new for each loop to iterate through array items. The first loop will output 0,1,2. The new loop will output the property names, item1, item2, item3

  1. var myArray = ['item1', 'item2', 'item3'];
  2.  
  3. // original way
  4.  
  5. for(var i:int in myArray) {
  6. trace(i);
  7. }
  8.  
  9. // new for each in loop
  10.  
  11. for each(var j:String in myArray) {
  12. trace(j);
  13. }

Report this snippet  

You need to login to post a comment.