nodeListToArray
Converts a NodeList
to an array.
Use spread operator inside new array to convert a NodeList
to an array.
typescript
const nodeListToArray = <T = any>(nodeList: Iterable<T>) => [...nodeList];
typescript
nodeListToArray(document.childNodes); // [ <!DOCTYPE html>, html ]
// array like string
const caps = (x: string) => x.toUpperCase();
nodeListToArray("caps").map(caps); // ["C", "A", "P", "S"]