Use nested for loop to deal with multiple sets of data : Array Dimension « Array « Flash / Flex / ActionScript






Use nested for loop to deal with multiple sets of data

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){

        var cars:Array = new Array();
        cars.push(["maroon", 1997, "H"]);
        cars.push(["beige", 2000, "Chrysler"]);
        cars.push(["blue", 1985, "Mercedes"]);
        cars.push(["gray", 1983, "Fiat"]);
        
        for (var i:int = 0; i < cars.length; i++) {
            for (var j:int = 0; j < cars[i].length; j++) {
                trace("Element [" + i + "][" + j + "] contains: " + 
                      cars[i][j]);
            }
        }
    }
  }
}
Element [0][0] contains: maroon
Element [0][1] contains: 1997
Element [0][2] contains: H
Element [1][0] contains: beige
Element [1][1] contains: 2000
Element [1][2] contains: Chrysler
Element [2][0] contains: blue
Element [2][1] contains: 1985
Element [2][2] contains: Mercedes
Element [3][0] contains: gray
Element [3][1] contains: 1983
Element [3][2] contains: Fiat

        








Related examples in the same category

1.Working with Single-Dimension Arrays
2.Multidimensional Arrays
3.Create a single array in which each element is a string containing both pieces of data, separated by a delimiter such as a colon (:)
4.The idea behind parallel arrays is to create two (or more) arrays in which the elements with the same indices are related.
5.Working with Multidimensional Arrays
6.With multidimensional arrays, concat( ) or slice( ) only duplicates the top level of the array
7.Storing Complex or Multidimensional Data
8.Working with multiple sets of data: create a multidimensional array
9.You can specify the properties of the object in any order you like
10.Creating an Associative Array
11.Create an associative array by adding properties to object
12.Compose dynamic properties
13.Two ways to add properties to dynamic object
14.Reading Elements of an Associative Array