Skip to content

Instantly share code, notes, and snippets.

@lcy101u
Created March 30, 2022 17:18
Show Gist options
  • Save lcy101u/025ea5b9430d5c56390b3e065f0fd7b2 to your computer and use it in GitHub Desktop.
Save lcy101u/025ea5b9430d5c56390b3e065f0fd7b2 to your computer and use it in GitHub Desktop.
javaScript Array.splice()
const array = ['A', 'B', 'C', 'D', 'E']
array.splice(0, 1) //從索引 0 的位置開始,刪除 1 個元素。 ['B', 'C', 'D', 'E']
array.splice(0, 0, 'P') //從索引 0 的位置開始,新增 'P'。 ['P', 'B', 'C', 'D', 'E']
array.splice(1, 3, 'Z', 'X') //從索引 1 的位置開始,刪除 3 個元素,新增 'Z'、'X'。 ['B', 'Z', 'X']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment