Created
March 30, 2022 17:18
-
-
Save lcy101u/025ea5b9430d5c56390b3e065f0fd7b2 to your computer and use it in GitHub Desktop.
javaScript Array.splice()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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