SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: array issue

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    array issue

    hi javascript people,

    I am trying to create an multidimensional array but every time I create it I get errors that [0][0] is undefined
    can anyone point tell me where I am going wrong

    Code:
    var currentOrder = [];
    currentOrder[0]= new Array(0);
    currentOrder[1]= new Array(1);
    currentOrder[2]= new Array(2);
    currentOrder[3]= new Array(3);
    currentOrder[4]= new Array(4);
    currentOrder[5]= new Array(5);	 
    document.writeln(currentOrder[5][5]+'<br>');

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With new Array(X), X = the number of elements in that array, so what are you trying to do with new Array(0)?

    Also, with

    currentOrder[5]= new Array(5);

    The last element in that row will be [5][4] because array indexes start at 0 not 1.

    A 2 dimensional array is simply an array of arrays.

  3. #3
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Replace

    currentOrder[0]= new Array(0);

    into

    currentOrder[0]= new Array(1);

    (or more than 1 element if you need more)


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
  •