⭐️ 注意:arr.splice() 會截斷原陣列、插入新元素,並回傳「被截掉的部分」❗️)
// splice here ↴ // 0 1 | 2 3 let fish = ['angel', 'clown', 'mandarin', 'sturgeon'] // ╰── ⭐️ fish ───╯ ╰──── ⭐️ removed ─────╯ // (after splice) // fish === ['angel', 'clown'] // ⭐️ original arr let removed = fish.splice(2) // "removed" will be returned
.splice() - 截斷原陣列、插入新元素。(⭐️ 注意:會回傳「被截掉的部分」❗️)
don't get confused with arr.slice().
there's another str.splice() for strings.
Last updated 1 year ago