Files
30-seconds-of-code/snippets/nodeListToArray.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

20 lines
410 B
Markdown

---
title: NodeList to array
tags: browser,array
cover: colors-mural
firstSeen: 2018-05-06T18:11:21+03:00
lastUpdated: 2020-10-21T21:54:53+03:00
---
Converts a `NodeList` to an array.
- Use spread operator (`...`) inside new array to convert a `NodeList` to an array.
```js
const nodeListToArray = nodeList => [...nodeList];
```
```js
nodeListToArray(document.childNodes); // [ <!DOCTYPE html>, html ]
```