Let's say I have an HTMLCollection:
const appElem = document.querySelector("#app");
const appChildren = appElem?.children; // HTML collection
now if I convert this collection to an array it will be Element[]
:
const appChildrenArr = appChildren && Array.from(appChildren); // Element[]
But why appChildrenArr
has Element[]
type, not HTMLElement[]
type?
Because they don't have to be HTMLElements. You could have an SVGElement there, as well, for example.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.