Question 8
Back to Exercise
Why is for…in a poor choice for looping over an array?
- A It cannot read arrays at all
- B Indexes arrive as strings, and extra or inherited enumerable properties are included too Correct
- C It always loops in reverse order
- D It skips the first element
Correct Answer: Option B
total += i would concatenate "0", "1", …, and arr.extra = 1 or a polyfill on Array.prototype would show up as a key. for…of gives the values cleanly.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!