Skip to content

[javascript] 清空 array 的方法介紹與比較(new、pop 及 shift...等)

Published: at 02:49 PM

紀錄一下幾個 javascript 清空陣列的方法比較。

來看看上面這幾個清空陣列的 jsperf 效能比較:https://jsperf.com/array-destroy/40

在多數瀏覽器,popshift 的方法最有效率,但在 firefox new 的方法效率遠大於其他方法。

參考資料:

http://www.jstips.co/en/javascript/two-ways-to-empty-an-array/