Posted By

aviddv1 on 08/24/07


Tagged

textmate array copy make of exact


Versions (?)

Clone Array


 / Published in: ActionScript
 

  1. // set clone items function
  2. function CLONE_ITEMS (itemsArray) {
  3. // create temp items array
  4. tempItems = new Array();
  5. // loop through each object in items array
  6. for (currentItem in itemsArray) {
  7. // create new object for current item
  8. tempItems[currentItem] = new Object();
  9. // loop through current item
  10. for (currentObject in itemsArray[currentItem]) {
  11. //
  12. tempItems[currentItem][currentObject] = itemsArray[currentItem][currentObject];
  13. }
  14. }
  15. //
  16. return tempItems;
  17. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: badabam on February 10, 2009

There is a much shorter way in AS3:

var a:Array = [1, 2, 3, 4, 5]; var b:Array;

b = a.map(function(e:*, ...r):*{ return e });

Posted By: badabam on February 10, 2009

in my last post, there must be an asterisk after "e:" - it did not get through

Posted By: aviddv1 on September 7, 2010

should be b = a.map(function(e:*, ...r):*{ return e });

Posted By: aviddv1 on September 7, 2010

should be b = a.map(function(e:*, ...r):*{ return e });

You need to login to post a comment.