Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPiotr Manczak
Front End Web Development Techdegree Graduate 29,363 PointsIs HTML Collection not an array but an object? When I log into console typeof(lis) it shows object not array.
Is HTML Collection not an array but an object? When I log into console typeof(lis) it shows object not array. Also I can not use forEach() on it, however for in loop works perfectly fine. If that is the case why can I use for loop to iterate over lis as well?
2 Answers
Steven Parker
231,269 PointsAn HTMLCollection
is what is known as an "array-like object", which is iterable and offers a few methods and properties for selecting items within it.
Another interesting aspect is that it is "live", meaning that it is updated whenever changes are made to the DOM.
For more details, see the MDN page on HTMLCollection.
Piotr Manczak
Front End Web Development Techdegree Graduate 29,363 PointsThank you Steven Parker. You are always there with answers. You are my hero!