PDA

View Full Version : Help with array



magicgavin
08-06-2007, 02:58 AM
i have the following code:


var my_deck=new Array(1,2,3,4,5);
var area_deck=new Array();
function ShuffleDeck(){
area_deck=my_deck;
area_deck[0]="a";
alert(my_deck)
}
ShuffleDeck()


The part that I don't understand is that when the alert pops up it shows...



a,2,3,4,5


Why is this happening and how can I fix it. I don't see how the "a" ends up in the my_deck array when i made the change to the area_deck.

Kenny
08-06-2007, 03:44 AM
Its in the sequence of your statements.

magicgavin
08-06-2007, 11:47 AM
So how do I fix it so this does not happen?

magicgavin
08-06-2007, 11:54 AM
var my_deck=new Array(1,2,3,4,5);
var area_deck=new Array();
function ShuffleDeck(){
arena_deck=my_deck.slice(0,my_deck.length);
area_deck[0]="a";
alert(my_deck)
}
ShuffleDeck()




Thanks for your help!