Convert NodeList to array

后端 未结 4 1628
不知归路
不知归路 2021-01-12 03:25

I\'m having a hard time converting a NodeList to an array in IE 8. The following works perfectly in Chrome, but in IE 8 toArray() is not recognize

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-12 03:37

    If you're looking for a modern answer using ES6:

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from

    var nodes = document.querySelectorAll('div');
    nodes = Array.from(nodes);
    

提交回复
热议问题