Fastest way to convert JavaScript NodeList to Array?

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

    The most fast and cross browser is

    for(var i=-1,l=nl.length;++i!==l;arr[i]=nl[i]);
    

    As I compared in

    http://jsbin.com/oqeda/98/edit

    *Thanks @CMS for the idea!

    Chromium (Similar to Google Chrome) Firefox Opera

提交回复
热议问题