The following code does the exact same thing. Is there a difference between for each and for (... in ...)?
var bar:Array = new Array(1,2,3);
for (var foo in bar){
trace(foo);
}
for each (var foo2 in bar){
trace(foo2);
}
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.
No, they do not do the exact same thing.
The output of your for..in loop is
While the output of your for each..in loop is
A for..in loop iterates through the keys/indices of an array or property names of an object. A for each..in loop iterates through the values. You get the above results because your
bararray is structured like this: