The slice (array) task extracts a section of an array and returns a new array that contains a portion of the original (source) array. Of note, the task does not change the source array; the original remains unchanged.
Potential Use Case
You have a large incoming array, the populated values for which are arrays unto themselves. Your immediate effort only needs to use specific values known to be populated in exact locations of the original array. Instead of using pop (array) and altering the length of the original incoming array, you use slice (array) to obtain a smaller subset of content for your immediate processing need. This provides for faster processing in 'for' loops.
Input and output properties are shown below.
||Array (required)||The array to slice.|
||Number (required)||Specifies where to start the extraction. The first element of an array is always indexed at 0 (i.e., zero-based). If omitted (undefined), the task defaults to the "0" index.|
||Number (required)||Specifies where to end the extraction. If omitted (undefined), the entire length of the array will be selected; this includes all elements from the start to the end of the array.|
||Array||A new array containing the extracted elements.|
In the IAP examples shown below:
All incoming property variables are required. As an option, you can toggle the Run Window slider to set the task to run on a schedule.
The array variables and the indexes to
endthe extraction are set prior to running the workflow. The
beginindex is "1" and the index at which to
endextraction is "4". More specifically,
slice(1,4)extracts the second element through the third-to-last element in the array sequence.
Note: A negative index can be used to select from the end of an array. For example,
slice(2,-1)extracts the third element through the second-to-last element in a sequence. The
arraySlicetask does not include the last given element.
Once the workflow is executed, the incoming variables are displayed under the Incoming tab in Task History, which is accessed from Job Manager. The indexes to begin/end extraction are also displayed.
The Outgoing tab displays the return value, which is the result of the
slicedArrayvariable. Based on the parameters passed in the input variables, the new array ("b", "c", "d") contains a portion of the original source array.
For general information on how to use tasks in Automation Builder, refer to the Tasks section in the Automation Studio documentation.