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

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

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

Removing the First Element of an Array: shift() method removes the element from the beginning of the array.

 
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var aEmployees:Array = ["A", "P", "C", "H"];
        var sAnEmployee:String = String(aEmployees.shift());
        trace(aEmployees.toString());
        trace(sAnEmployee);
    }
  }
}
//P,C,H
//A



shift( ) removes an element from the beginning of an array: theArray.shift( )

 
shift( ) returns the value of the element it removes. 
The remaining elements all move up in the pecking order toward the beginning of the array.

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

        var sports:Array = ["q", "s", "i"];
        trace(sports.shift(  ));  
        trace(sports.shift(  ));  

    }
  }
}



The shift( ) method removes the first element of the array and returns its value.

 
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var letters:Array = ["a", "b", "c", "d"];
             
        trace(letters.shift(  ));
    }
  }
}