Duplicating an array

AS3:

var array1:Array=[5,7,121,2434,5656,575]; 
var array2:Array = new Array(); 
array2=array1.concat(); 
trace(array2); 

AS2:
little did you know, that you can’t jsut go
array_b = array_a;

as that just refers to the same array
isn’t that annoying? I know you think so too.

So you can use this to duplicate an array. Don’t ask me how it works but it does.

// Credits: FlashGuru
Array.prototype.copy=Array.prototype.slice;
// test
tester=[1,2,3,4];
tester2=tester.copy();
tester.pop();
trace (tester2);

Tech Reference:

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑