In the following code why the variable ‘a’ refer to the index rather than the value ?
for (var a in Values) {
alert(Values[a]);
}
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.
Think of a JavaScript Array as a normal Object with a special property named
length(actually, it a bit more complex). So the for..in loop behaviour is identical as for other objects:Also note that you can have gaps within your array without having to pay the memory price.