why does the following indexOf(searchElement:T, fromIndex:int = 0):int not find the object and return -1?
var v:Vector.<Object> = new Vector.<Object>();
v.push({name:"Geoffrey", age:32});
trace(v.indexOf({name:"Geoffrey", age:32}));
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Simple answer is that
Vector.indexOf()searches by reference. In your code you have created two, completely separate objects; they may look identical to you, but that’s because you’re a human 🙂If you want to find the index of an object based on its properties you will want to use a
foriloop.