Fastest way to convert JavaScript NodeList to Array?

前端 未结 13 1842
清酒与你
清酒与你 2020-11-22 16:48

Previously answered questions here said that this was the fastest way:

//nl is a NodeList
var arr = Array.prototype.slice.call(nl);

In benc

13条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 17:48

    With ES6, we now have a simple way to create an Array from a NodeList: the Array.from() function.

    // nl is a NodeList
    let myArray = Array.from(nl)
    

提交回复
热议问题