2 Replies Latest reply on Jul 19, 2006 3:27 PM by CogDev

    2 dimensional arrays...

    DZ-015
      The title pretty much says it all...

      I just want to know how to create and how to reference 2 (or more) dimensional arrays.

      Thanks
        • 1. Re: 2 dimensional arrays...
          kglad Adobe Community Professional & MVP
          try:

          • 2. Re: 2 dimensional arrays...
            CogDev Level 1
            It's pretty straightforward, all you have to do is assign a variable to an array that contains arrays.

            To reference them, just have the first index, followed by the second index. Here's an example:

            // This will output the Multiplication table from 0 to 9 using a 2 dimensional array
            var numberArray = [[null],[null],[null],[null],[null],[null],[null],[null],[null],[null]];

            for(var i=0; i < 10; i++){
            for(var j=0; j < 10; j++){
            numberArray [j] = j*i;
            }
            trace(numberArray
            );
            }

            I hope that helps. I wish I knew exactly why you have to initialize the array to the length you want it to be, but if you don't you'll "undefined". There are probably better ways of doing this.