This was a lifesaver for me. Array.map will run a function on every item of an array and construct a new array based on what is returned from the function call. I don’t have a demo, but this is from Adobe:
package {
import flash.display.Sprite;
public class Array_map extends Sprite {
public function Array_map() {
var arr:Array = new Array("one", "two", "Three");
trace(arr); // one,two,Three
var upperArr:Array = arr.map(toUpper);
trace(upperArr); // ONE,TWO,THREE
}
private function toUpper(element:*, index:int, arr:Array):String {
return String(element).toUpperCase();
}
}
}
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.