---
schema_version: "1"
id: 35c74c481f063c9acf0c6b7869443eb84cee3c5305c387a2d6649ea31ca5f330
title: "Handlebars Helper Function: slice"
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/handlebars/reference/objects/mcn-handlebars-reference-objects-slice.md
canonical_url: https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-objects-references/mcn-handlebars-reference-objects-slice.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 004f1b30cd34c437f6e34be75148ea33b4dd4e1bd59fb6488a03b354104dbcaf
products:
  - Handlebars for Marketing Cloud Next
  - Marketing Cloud
---
# Handlebars Helper Function: slice

Returns a portion of a list between two specified indices, similar to JavaScript's `Array.slice()`.

## Availability

This helper is available in the Winter ’26 release of Marketing Cloud Next.

## Syntax

```handlebars
{{slice list startIndex endIndex}}
```

## Parameters

| Parameter    | Type    | Description                                                                                                                                                                   |
| ------------ | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `list`       | Array   | Required. The list to slice.                                                                                                                                                  |
| `startIndex` | Integer | Required. The starting index. Use negative indices to count from the end.                                                                                                     |
| `endIndex`   | Integer | The ending index. Use negative indices to count from the end. If you don’t specify an end index, the function returns a sublist from the `startIndex` to the end of the list. |

## Return Value

The function returns a sublist from `startIndex` to `endIndex`, not including the element at the `endIndex`. List indices start at 0. If indices are out of bounds or invalid, the function throws an exception. If the array is empty, the function returns an empty list.

## Usage Examples

This example shows how to use the `slice` function to return a sublist.

```javascript
myList = ["apple", "banana", "cherry", "date", "elderberry"];

{{slice myList 1 3}}
```

The function returns `["banana", "cherry"]`.

### Slice from the `startIndex` to the End of the List

If you don't specify an end index, the function returns a sublist from the `startIndex` to the end of the list, as shown in this example.

```javascript
myList = ["apple", "banana", "cherry", "date", "elderberry"];

{{slice myList 2}}
```

The function returns `["cherry", "date", "elderberry"]`.

### Index from the End of the List

You can also use negative indices to index the list from the end. Negative indices start at -1. The element at the `endIndex` isn’t included in the sublist, regardless of whether it’s positive or negative.

This example shows how to use negative indices to index the list from the end.

```javascript
myList = ["apple", "banana", "cherry", "date", "elderberry"];

{{slice myList -2 -1}}
```

The function returns `["date"]`.

### Combine Positive and Negative Indices

You can also specify a positive `startIndex` and a negative `endIndex`. This example shows how to return a list that includes the second through the second-to-last elements.

```javascript
myList = ["apple", "banana", "cherry", "date", "elderberry"];

{{slice myList 1 -1}}
```

The function returns `["banana", "cherry", "date"]`.
