Is Htmlcollection An Array?
I understand that HTMLCollection is not actually an array, or else it would be defined as an array. I use a help function that I call isArray() to detect whether or not an object i
Solution 1:
No, it's an HTMLCollection
, not an Array
.
It has Array-like characteristics, like numeric properties, and a .length
property, but it does not inherit from Array.prototype
. Therefore it does not have the standard Array
methods, and so should be seen as being different.
Another significant difference is that HTMLCollection
is a "live" collection, which means that it updates as the DOM updates. If you remove one of its nodes from the DOM, it will be removed from the HTMLCollection
automatically.
Solution 2:
If you are considering an Array conversion, please refer to this post:
Most efficient way to convert an HTMLCollection to an Array.
They discussed some methods, and the solution in the selected answer also worked in a situation I´ve experienced.
Post a Comment for "Is Htmlcollection An Array?"