> 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.slice.md).

# arr.slice()

{% hint style="warning" %}
arr.slice() returns a <mark style="color:yellow;">**new array**</mark>.
{% endhint %}

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

```javascript
// slice           0       1        2        3         4
const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
// ⭐️ new array                  ╰─slice(2, 4)─╯

// 2 <= index < 4
animals.slice(2,4)      // ['camel', 'duck']  
```

{% endtab %}

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

* .[slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)() - 擷取某一段，產生**新陣列**。
  {% endtab %}

{% tab title="⬇️ 應用" %}

* [arr.copy()](/web/js/val/builtin/arr/ext/arr.copy.md) - returns a copy of the original array.
  {% endtab %}

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

* don't get confused with [arr.splice()](/web/js/val/builtin/arr/method/arr.splice.md).
* [arr.copy()](/web/js/val/builtin/arr/ext/arr.copy.md)
  {% endtab %}
  {% endtabs %}
