TwelvestoneFlash

copy array


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
katdesign
 
2003-02-04

Just wondering, can you just copy an array into a new location like this:

newarray = oldarray;

like you would do when defining any variable?

sakri
 
2003-02-04

you need to use slice() to create a new copy of an array... the folowing illustrates the case:

my_array=new Array(1,2,3,4,5); my_copy=my_array; my_copy.length=3; trace("my_array = {"+my_array+"}"); trace("my_array = {"+my_copy+"}"); delete my_array,my_copy; my_array=new Array(1,2,3,4,5); my_copy=my_array.slice(); my_copy.length=3; trace("my_array = {"+my_array+"}"); trace("my_array = {"+my_copy+"}");

output:

my_array = {1,2,3} my_array = {1,2,3} my_array = {1,2,3,4,5} my_array = {1,2,3}

sakri
 
2003-02-04

oh, by the way, welcome to 12stone k

katdesign
 
2003-02-04

thx for the welcome k it's nice to find a worthy replacement for the godlike were-here, i hope Jess gets it online again some time in the (hopefully near) future...

sakri
 
2003-02-04

there's a lot of very negative talk going around saying it will go the way of flashpad... oh well... might as well make the best of this place k

garyalfred
 
2003-02-04

Yes.. you can.

first = new Array("a","b","c"); second = first; first = "";// just to make sure we're not creating a pointer. trace(second.join("|"));

output a|b|c

katdesign
 
2003-02-04

thanks, that was just what i needed! Only, i discovered that it wasn't necessary for what i wanted to do, so i actually don't need it anymore. I'll try to remember it, though, for later k

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

copy array