Flash / Flex / ActionScript/Array/unshift — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 09:19, 26 мая 2010
Arrays can call unshift() to add any number of elements to the front of the array just like push().
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var queue:Array = new Array();
queue.push("A");
queue.push("J");
queue.push("W");
queue.unshift("J", "D");
trace(queue); // Displays: Jim,Doro,James,Will
}
}
}
Prepending Elements to the Beginning of an Array: the unshift() method
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var aEmployees:Array = ["A", "P", "C", "H"];
aEmployees.unshift("R", "H", "L");
trace(aEmployees.toString());
}
}
}
unshift( )method adds one or more elements to the beginning of the array: theArray.unshift(item1, item2,...itemn);
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var versions:Array = new Array( );
versions[0] = 6;
versions.unshift(5); // versions is now [5, 6]
versions.unshift(2,3,4); // versions is now [2, 3, 4, 5, 6]
trace(versions); // 2,3,4,5,6
}
}
}