Flash as3 - how to find the index of an object in an array

How do you find the object index / position inside an array in flash actionscript 3? I am trying to set a condition in a loop where, if the object identifier is equal to the current_item variable, I can return its position in the array.

+4
source share
1 answer

Something like this might help you - in this example, the position of value 7 is returned:

private var _testArray:Array = new Array(5, 6, 7, 8, 9, 8, 7, 6); public function ArrayTest() { trace (_testArray.indexOf(7)); //Should output 2 } 

therefore for your needs:

  item variableToLookFor = 9 // Your variable here private var _testArray:Array = new Array(5, 6, 7, 8, 9, 8, 7, 6); public function ArrayTest() { trace (_testArray.indexOf(variableToLookFor)); //Should output 4 } 

This will return -1 if your element does not exist, otherwise it will output a position in the array.

If you need more information, you can check here for an article on AS3 arrays.

+14
source

Source: https://habr.com/ru/post/1340994/


All Articles