Fastest way to convert JavaScript NodeList to Array?

前端 未结 13 1876
清酒与你
清酒与你 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:28

    Here are charts updated as of the date of this posting ("unknown platform" chart is Internet Explorer 11.15.16299.0):

    Safari 11.1.2 Firefox 61.0 Chrome 68.0.3440.75 Internet Explorer 11.15.16299.0

    From these results, it seems that the preallocate 1 method is the safest cross-browser bet.

提交回复
热议问题