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; } } } }
|
|
|
|
|
|
Flash / Flex / ActionScript examples
| Array » Map |
|
|