With multidimensional arrays, concat( ) or slice( ) only duplicates the top level of the array : Array Dimension « Array « Flash / Flex / ActionScript






With multidimensional arrays, concat( ) or slice( ) only duplicates the top level of the array

 

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

        var coordinates:Array = new Array(  );
        coordinates.push([0,1,2,3]);
        coordinates.push([4,5,6,7]);
        coordinates.push([8,9,10,11]);
        coordinates.push([12,13,14,15]);
        
        var coordinatesDuplicate:Array = coordinates.concat(  );
        
        coordinatesDuplicate[0][0] = 20;
        trace(coordinates[0][0]);  // Displays: 20
        
        coordinatesDuplicate[1] = [21,22,23,24];
        trace(coordinates[1]);  // Displays: 4,5,6,7
        
    }
  }
}
20
4,5,6,7

        








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.Storing Complex or Multidimensional Data
7.Working with multiple sets of data: create a multidimensional array
8.Use nested for loop to deal with multiple sets of data
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