I am calling this on an array with 3 objects in it. It ends up returning the correct keys in addition to these extra keys…
unique
last
truncate
random
include
contains
any
Why?
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.
You’re getting those extra properties because you, or a library you’re using, has extended the
Arrayprototype. As Mike points out in his answer, you can skip those by usinghasOwnProperty. Indeed, CoffeeScript has anownkeyword built in that does this for you:But, as Mike also points out in his answer, it’s more efficient to loop through an array by incrementing a counter rather than iterating over the keys. To do that, you’d use CoffeeScript’s
for...insyntax:(If you need indices in the loop as well, you can write
for obj, i in foo.)