> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/val/builtin/arr/method/arr.splice.md).

# arr.splice()

{% hint style="warning" %}
⭐️ 注意：[<mark style="color:blue;">arr.splice()</mark>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) 會<mark style="color:red;">**截斷原陣列**</mark>、<mark style="color:yellow;">**插入新元素**</mark>，並回傳「<mark style="color:orange;">**被截掉的部分**</mark>」❗️)
{% endhint %}

{% tabs %}
{% tab title="💈範例" %}

```javascript
//              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
```

{% endtab %}

{% tab title="📘 手冊" %}

* .[splice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)() - 截斷**原陣列**、插入新元素。(⭐️ 注意：會回傳「**被截掉的部分**」❗️)
  {% endtab %}

{% tab title="👥 相關" %}

* don't get confused with [arr.slice()](/web/js/val/builtin/arr/method/arr.slice.md).
* there's another [str.splice()](/web/js/val/prim/str/method/str.splice.md) for strings.
  {% endtab %}
  {% endtabs %}
