Fastest way to duplicate an array in JavaScript - slice vs. 'for' loop

后端 未结 22 1506
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 02:10

In order to duplicate an array in JavaScript: which of the following is faster to use?

###Slice method

var dup_array = original_array.slice();
<         


        
22条回答
  •  梦如初夏
    2020-11-22 02:53

    I put together a quick demo: http://jsbin.com/agugo3/edit

    My results on Internet Explorer 8 are 156, 782, and 750, which would indicate slice is much faster in this case.

提交回复
热议问题