- 20 Dec 2023
-
DarkLight
-
PDF
slice (array)
- Updated on 20 Dec 2023
-
DarkLight
-
PDF
Task Purpose
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.
Task Properties
Input and output properties are shown below.
Incoming | Type | Description |
---|---|---|
arr |
Array (required) | The array to slice. |
begin |
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. |
end |
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. |
Outgoing | Type | Description |
---|---|---|
slicedArray |
Array | A new array containing the extracted elements. |
How to Configure the Task
In the IAP examples shown below:
-
All incoming property variables are required. As an option, you can select the Advanced tab and toggle the Run Window slider to set the task to run on a schedule.
-
The array variables and the indexes to
begin
andend
the extraction are set prior to running the workflow. Thebegin
index is "1" and the index at which toend
extraction is "4". More specifically,slice(1,4)
extracts the second element through the third-to-last element in the array sequence.
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 arraySlice
task 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 Jobs in Operations Manager. The indexes to begin and end the extraction are also displayed.
- The Outgoing tab displays the return value, which is the result of the
slicedArray
variable. Based on the parameters passed in the input variables, the new array ("b", "c", "d") contains a portion of the original source array.