0
var arr1:Array = new Array();
arr1.push(item1);
arr1.push(item2);
arr1.push(item3);

then arr1 and its elements get passed to other functions is there a way to know the index of an item in the array?

GetParentArrayIndex(item2) would give me 1;

2 Answers 2

2

Array's have built in functionality for this, myArray.indexOf(obj)

Sign up to request clarification or add additional context in comments.

Comments

0

presumably you set a function like:

public function GetParentArrayIndex(item:Object):int
{
    for(var i=0; i<arr1.length; i++){
        if(arr1[i] == item){
            return i;
        }
     }
     return -1 //Item not found
} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.