What is the difference between nodelist and array in javascript? Can we convert array to nodelist?
Asked
Active
Viewed 132 times
0
-
Check this for conversion...http://davidwalsh.name/nodelist-array – Nikhil N Oct 21 '13 at 12:09
1 Answers
0
I can give you the reference at most:
NodeList objects are collections of nodes returned by Node.childNodes and the querySelectorAll method.
The JavaScript Array global object is a constructor for arrays, which are high-level, list-like objects.
And here is David Walsh's blog : Convert NodeList to Array which suggest:
var nodesArray = Array.prototype.slice.call(document.querySelectorAll("div"));

xkeshav
- 53,360
- 44
- 177
- 245
-
-
1once user know what both is, then it will be easy to identify the differences – xkeshav Oct 21 '13 at 12:12
-
In particular, from [MDN NodeList page](https://developer.mozilla.org/en-US/docs/Web/API/NodeList): `NodeList.prototype contains the item method, but none of the Array.prototype methods, so they cannot be used on NodeLists.` – Alberto De Caro Oct 21 '13 at 12:20
-