HTMLCollection may looks like an Array but it isn't, hence the Array.from() or [...copiedContents], since you'll need to transform it on an actual array for performing some array-like operations.
Doing so changes the iterable data structure: it is, indeed, not the original copiedContents, but the insides are the same DOM references to elements, you didn't make new ones. This article should help you understand it a bit.
Got it. So, copying the HTMLCollection into a new array using Array.from() also copied all of the references to the original, thus changes to the copy reflected back to the DOM. That seems convenient and dangerous at the same time.
This is the nature of working with DOM elements, don't know if I'm just used to it. It's very reference-y and with a bunch of side-effects, I believe that's why we use libs like React, since we almost don't have to deal with this.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
HTMLCollection
may looks like an Array but it isn't, hence theArray.from()
or[...copiedContents]
, since you'll need to transform it on an actual array for performing some array-like operations.Doing so changes the iterable data structure: it is, indeed, not the original
copiedContents
, but the insides are the same DOM references to elements, you didn't make new ones. This article should help you understand it a bit.Got it. So, copying the
HTMLCollection
into a new array usingArray.from()
also copied all of the references to the original, thus changes to the copy reflected back to the DOM. That seems convenient and dangerous at the same time.Yeah, right!
This is the nature of working with DOM elements, don't know if I'm just used to it. It's very reference-y and with a bunch of side-effects, I believe that's why we use libs like React, since we almost don't have to deal with this.