Flash / Flex / ActionScript/Array/slice — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 09:19, 26 мая 2010
slice() accepts negative numbers, which count from the end of the array rather than the beginning.
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var metals:Array = ["iron", "copper", "gold", "silver", "platinum", "tin","chrome"];
var canMakingMetal:Array = metals.slice(-2,-1);
trace(canMakingMetal); // Displays: tin
}
}
}
Working with a Subset of Your Array with slice()
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var metals:Array = ["iron", "copper", "gold", "silver","platinum", "tin", "chrome"];
var preciousMetals:Array = metals.slice(2,5);
trace(preciousMetals); // Displays: gold,silver,platinum
}
}
}