pop

@pop

Contributes1

Followers0

@pop

Stories List
@qinglong_62898aa51988d

為什麼 shift 比 pop 慢?JS 中隊列的實現

我們知道在 JS 中,刪除數組元素有兩個方法:pop 與 shift,分別可以刪除末尾與開頭的元素。 然而同樣是刪除元素,它們的執行時間確實不同的。 當數組項目較多時,shift 的執行時間明顯長於 pop。 const test = (arrLength) = { let arr1 = [] console.time(`${arrLength}-arr1`) for (let i =