0

slice

To extract a subrange from a string or array

This function helps you to extract a partial range of an array and transfer it to a new array. You define the part you want to extract by a start and an end position. Start and end position start with 0.

💡 The start is inclusive, the end is exclusive. If the end value is larger than the total number of array elements, the array will be extracted from a given start until the end of the array.

Use this function also to get an extract out of a text. In this case, each character of the text corresponds to an array element.

Syntax

slice([any], number, number)

slice(string, number, number)

Return

[any]

More about any >

string

Examples

slice(array, start, end) To extract a sub-array. Start and end are zero-based.

slice(["Apple","Bagel","Cake","Donut"], 1, 3)

Result: Bagel,Cake

slice(text, start, end) To extract a text piece. Start and end are zero-based.

slice("Mermaid", 3, 7)

Result: maid

See also

item which extracts a value of an array or an object.

substr which returns a substring out of a given text

substring which returns a new string out of a given text with a given start and a given end

Reply

null