Getting Results with the map() Method : Map : Array Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Array » Map »

 

Getting Results with the map() Method


 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var myArray:Array = [1,2,3,4,5];
        
        var squaredArray:Array = myArray.map(getSquare);
        trace(myArray);      // Displays: 1,2,3,4,5
        trace(squaredArray)// Displays: 1,4,9,16,25

    }
    function getSquare(elem:*, i:int, a:Array):Number {
        if (isNaN(elem)) {
            return -1;
        else {
            return elem * elem;
        }
    }
  }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo Array
» Map