var fruits:Array = new Array("apples", "oranges", "grapes", "pears");
for each (var fruit:String in fruits ) {
trace(fruit); //Outputs apples, oranges, grapes, pears
}
Welcome to my actionscript snippet library!
Actionscript Snips is a small repository of actionscript code that aims to save developers and designers time when developing a website.
Showing posts with label Arrays. Show all posts
Showing posts with label Arrays. Show all posts
Traversing Array Using For Each Loop
Find Min/Max Of Array Of Integers
var min:Number;
var max:Number;
var numbers:Array = new Array(3, 5, 2, 1, 4);
function findMin(array:Array):Number {
min = array[0];
for (var i = 0; i < array.length; i++) {
if (array[i] < min) {
min = array[i];
}
}
return min;
}
function findMax(array:Array):Number {
max = array[0];
for (var i = 0; i < array.length; i++) {
if (array[i] > max) {
max = array[i];
}
}
return max;
}
trace(findMin(numbers)); //Outputs 1
trace(findMax(numbers)); //Outputs 5