Posted By

orazal on 09/17/08


Tagged


Versions (?)

Array Loop


 / Published in: ActionScript
 

  1. var testArray:Array = ["one", "two", "three", "four"];
  2. trace(testArray);
  3. trace("Last to first");
  4. // Bring last item to beginning of array
  5. testArray.unshift(testArray.pop());
  6. trace(testArray);
  7. testArray.unshift(testArray.pop());
  8. trace(testArray);
  9. testArray.unshift(testArray.pop());
  10. trace(testArray);
  11. trace("First to last");
  12. // Bring first item to the end of array
  13. testArray.push(testArray.shift());
  14. trace(testArray);
  15. testArray.push(testArray.shift());
  16. trace(testArray);
  17. testArray.push(testArray.shift());
  18. trace(testArray);
  19.  
  20.  
  21. /*
  22.  * Output
  23.  *
  24. Last to first
  25. one,two,three,four
  26. four,one,two,three
  27. three,four,one,two
  28. two,three,four,one
  29. First to last
  30. three,four,one,two
  31. four,one,two,three
  32. one,two,three,four
  33. */

Report this snippet  

You need to login to post a comment.