---
schema_version: "1"
id: 2903f95bed51c156a8faacc49b6256d8a783ce4b7b7ef61007c0b3995a735fdc
title: slice
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.6/dw-arrays-functions-slice.md
canonical_url: https://docs.mulesoft.com/dataweave/2.6/dw-arrays-functions-slice
source_site: docs.mulesoft.com
content_type: documentation
content_hash: fdbe150619d1c5c546e9722b07c63c2f3c2f05ef03310114e1ce0f6b13fd834c
description: MuleSoft Documentation Site
release: "2.6"
latest: false
---
---
product: DataWeave
version: 2.6
---

# slice

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## slice<T>(array: Array<T>, from: Number, until: Number): Array<T>

Selects the interval of elements that satisfy the condition: `from <= indexOf(array) < until`

_Introduced in DataWeave version 2.2.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>array</code></p></td><td><p>The array of elements.</p></td></tr><tr><td><p><code>from</code></p></td><td><p>The starting index of the interval of elements to include from the array.<br>If this value is negative, the function starts including from the first element of the array. If this value is higher than the last index of the array, the function returns an empty array (<code>[]</code>).</p></td></tr><tr><td><p><code>until</code></p></td><td><p>The ending index of the interval of elements to include from the array.<br>If this value is higher than the last index of the array, the function includes up to the last element of the array. If this value is lower than the first index of the array, the function returns an empty array (<code>[]</code>).</p></td></tr></tbody></table>

### Example

This example returns an array that contains the values of indices 1, 2, and 3 from the input array.
It excludes the values of indices 0, 4, and 5.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Arrays
output application/json
var arr = [0,1,2,3,4,5]
---
slice(arr, 1, 4)
```

#### Output

```json
[1, 2, 3]
```

## slice(array: Null, from: Any, until: Any): Null

Helper function that enables `slice` to work with a `null` value.

_Introduced in DataWeave version 2.4.0._
