slice (array)
  • 20 Dec 2023
  • Dark
    Light
  • PDF

slice (array)

  • Dark
    Light
  • PDF

Article summary

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 and end the extraction are set prior to running the workflow. The begin index is "1" and the index at which to end extraction is "4". More specifically, slice(1,4) extracts the second element through the third-to-last element in the array sequence.

Sliced%20array%20image%201


Sliced%20array%20image%202

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 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.

Sliced array image 4.jpg

  • 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.

Sliced%20array%20image%203


Was this article helpful?

What's Next
Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.