Let us know so we can improve!
The online Trailblazer Community is now read-only. [Read the FAQ] [Get Help]
Returns a portion of a list between two specified indices, similar to JavaScript’s Array.slice().
This helper is available in the Winter ’26 release of Marketing Cloud Next.
1{{slice list startIndex endIndex}}| 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. |
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.
This example shows how to use the slice function to return a sublist.
1myList = ["apple", "banana", "cherry", "date", "elderberry"];
2
3{{slice myList 1 3}}The function returns ["banana", "cherry"].
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.
1myList = ["apple", "banana", "cherry", "date", "elderberry"];
2
3{{slice myList 2}}The function returns ["cherry", "date", "elderberry"].
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.
1myList = ["apple", "banana", "cherry", "date", "elderberry"];
2
3{{slice myList -2 -1}}The function returns ["date"].
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.
1myList = ["apple", "banana", "cherry", "date", "elderberry"];
2
3{{slice myList 1 -1}}The function returns ["banana", "cherry", "date"].