Flash / Flex / ActionScript/Array/concat — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 08:14, 26 мая 2010

concat( ) does not flatten nested arrays

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var x:Array = [1, 2, 3];
        var y:Array = [[5, 6], [7, 8]];
        var z:Array = x.concat(y);  // Result is [1, 2, 3, [5, 6], [7, 8]].
        
        trace(z); //1,2,3,5,6,7,8
    }
  }
}



Creating New Arrays from Existing Arrays

 
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var aEmployeesExec:Array = ["A", "P", "C", "H"];
        var aEmployeesNew:Array = ["G", "M"];
        var aEmployeesStaff:Array = ["A", "R"];
        var aEmployeesAll:Array = aEmployeesExec.concat(aEmployeesNew, aEmployeesStaff);
        trace(aEmployeesAll.toString());
    }
  }
}
//A,P,C,H,G,M,A,R



The concat( ) method combines two or more arrays into a single, new array: origArray.concat(elementList)

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var list1:Array = new Array(11, 12, 13);
        var list2:Array = list1.concat(14, 15);  // list2 becomes
        
        trace(list2); // 11,12,13,14,15
    }
  }
}



Use concat to combine two arrays

 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var guests:Array = ["P", "D"];
        var registeredPlayers:Array = ["G", "D", "T"];
        var allUsers:Array = registeredPlayers.concat(guests);
        
        trace(allUsers); // G,D,T,P,D
    }
  }
}