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 trial

JavaScript JavaScript and the DOM (Retiring) Traversing the DOM Getting All Children of a Node with children

Piotr Manczak
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Piotr Manczak
Front End Web Development Techdegree Graduate 28,940 Points

Is 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
Steven Parker
229,783 Points

An 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.