[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

shop_platform - 部署到 GCP (2)

JavaScript/ HTML/ CSS 工具資源

TCP/ IP 通訊協定