[javascript] 使用 array.forEach 時若刪掉陣列元素,有些元素會被跳過去

測試用程式碼

 const array = [0,1,2,3]
array.forEach((item, index) => {
  console.log('item:', item)
  array.splice(index, 1)
})
console.log(array)

印出了

item: 0
item: 2
[ 1, 3 ]

Comments

Popular posts from this blog

資料關聯

程式設計相關社群、活動

TCP/ IP 通訊協定