Searching through arrays

This works in both actionscript 2 and actionscript 3.

To search an array starting from the first position in the array we use:

  1. for (var i:int = 0; i < myArray.length; i++)
  2. {
  3. ...
  4. }

Where you would change myArray with the variable name of your array.

But what if you wanted to search through the array from the last item? Well the easiest way of doing this is by using:

  1. for (var i in myArray)
  2. {
  3. ...
  4. }

Now you know. And knowing is half the battle. - G.I. Joe

Leave a Reply