Results 1 to 4 of 4

Thread: Help with array

  1. #1
    Join Date
    Aug 2006
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help with array

    i have the following code:
    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...

    Code:
    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.

  2. #2
    Join Date
    Dec 2006
    Posts
    47
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Default

    Its in the sequence of your statements.

  3. #3
    Join Date
    Aug 2006
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    So how do I fix it so this does not happen?

  4. #4
    Join Date
    Aug 2006
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Code:
    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!
    Last edited by magicgavin; 08-06-2007 at 12:08 PM. Reason: Removed link and showed example

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •