www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Help - Begginer - Problem with matrix

  1. #1
    Join Date
    May 2014
    Posts
    2

    resolved [RESOLVED] Help - Begginer - Problem with matrix

    The code just keep giving me 6 or 8 independent of the position i'm trying to access.

    Code:
    var valueMatrix = 0;
    var matrix = [[0,0],[0,0],[0,0]];
       matrix[0,0,0] = 1;
       matrix[0,1,0] = 2;
       matrix[0,0,1] = 3;
       matrix[0,1,1] = 4;
       matrix[1,0,0] = 5;
       matrix[1,1,0] = 6;
       matrix[1,0,1] = 7;
       matrix[1,1,1] = 8;   
       
       
    function test() 
      {
        valueMatrix = matrix[0,0,0];
       alert(valueMatrix);
      }

    I dont know how to solve this...

    (sorry for my poor english)

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    862
    It looks like you're trying to work with a multi-dimensional array, in which case I believe what you want is:
    Code:
    var valueMatrix = 0;
    var matrix = [[[]], [[]], [[]]];
      matrix[0][0][0] = 1;
      matrix[0][1][0] = 2;
      matrix[0][0][1] = 3;
      matrix[0][1][1] = 4;
      matrix[1][0][0] = 5;
      matrix[1][1][0] = 6;
      matrix[1][0][1] = 7;
      matrix[1][1][1] = 8;   
    
    function test() {
      valueMatrix = matrix[0][0][0];
      console.log(valueMatrix);
    }
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    May 2014
    Posts
    2
    Yeah! It worked!

    Thanks for the support!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles