Add nodeListToArray
This commit is contained in:
13
snippets/nodeListToArray.md
Normal file
13
snippets/nodeListToArray.md
Normal file
@ -0,0 +1,13 @@
|
||||
### nodeListToArray
|
||||
|
||||
Converts a `NodeList` to an array.
|
||||
|
||||
Use `Array.prototype.slice()` and `Function.prototype.call()` to convert a `NodeList` to an array.
|
||||
|
||||
```js
|
||||
const nodeListToArray = nodeList => Array.prototype.slice.call(nodeList);
|
||||
```
|
||||
|
||||
```js
|
||||
nodeListToArray(document.childNodes); // [ <!DOCTYPE html>, html ]
|
||||
```
|
||||
Reference in New Issue
Block a user