Skip to main content
Array Utilities

Explore the array utility steps in Torq.

Updated over 3 months ago

Use these utility steps to work with arrays. See below for examples of each step's input and output.

Append to array

Adds an object (string, integer, etc.) to the end of an existing array or instantiates an array to which objects will later be added. If no array is given or the given array does not exist, the member will be added to an empty array.

Input

["joe", "jane", "jill"]

New_Member

"bob"

Output

["joe", "jane", "jill", "bob"]


Chunk array

Divides an existing array into smaller arrays.

Input

["joe", "jane", "jill", "bob", "doug", "mary"]

Chunk_Size

3

Output

[ [ "joe", "jane", "jill"], [ "bob", "doug","mary" ] ]


Concat arrays

Combines 2 arrays into a single array. Objects that appear in both arrays are duplicated in the concatenated result.

Input

["joe", "jane", "jill"]

Second_Array

["bob", "doug", "mary", "jill", "joe"]

Output

["joe", "jane", "jill","bob", "doug","mary", "jill", "joe"]


Delete from array

Deletes an object from the array. The step will delete the first matching object found in the array.

Input

["joe", "jane", "jill"]

Array object to delete

"jane"

Output

["joe", "jill"]


Extract field from records

Given a list of records and a field name, extract the value for the provided field name for each record.

Input

JSON

[ { "name": "John Doe", "details": { "age": 23 } }, { "name": "Jane Doe", "details": {"age": 97 } } ]

Field_Path

details.age

Output

[23, 97]


Filter array

Filters an array to produce a subset of the data based on the Filter_Func_ operator and Filter definition. The FieldPath is the location of the array within the input where the data is located. This path is only required when the dataset is nested.

Input

["joe", "jane", "jill","bob", "doug","mary", "jill", "joe"]

Filter_Func

"Contains"

*Field_Path *

""

Filter_Arg

j

Output

["joe", "jane", "jill", "jill", "joe"]


Get array length

Input

["joe", "jane", "jill"]

New_Member

"bob"

Output

["bob", "joe", "jane", "jill"]


Get last item from array

Returns the last object in the array.

Input

["joe", "jane", "jill","bob", "doug","mary" ]

Output

"mary"


Join strings

Returns a single string of all objects in the array separated by the delimiter.

Input

["joe", "jane", "jill","bob", "doug","mary" ]

Delimiter

||

Output

"joe||jane||jill||bob||doug||mary||jill||joe"


Prepend to array

Adds an object (string, integer, etc.) to the beginning of an existing array, or instantiates an array to which objects will later be added. If no array is given or the given array does not exist, the member will be added to an empty array.

Input

["joe", "jane", "jill"]

New_Member

"bob"

Output

["bob", "joe", "jane", "jill"]


Replace in array

Replaces an object in the array. The step will replace the first matching object found in the array.

Input

["joe", "jane", "jill", "jane"]

Object to replace

"jane"

New member

"bob"

Output

["joe", "bob", "jill", "jane"]


Reverse array

Reverses the order of the items in a given array.

Input

["joe", "jane", "jill", "bob"]

Output

["bob", "jill", "jane", "joe"]


Rollup numeric array

Performs a rollup function on an array of numbers.

Input

[1, 2, 3, 4, 5]

Rollup_Function

Product

Output

120


Slice array

Returns a slice of the given array, meaning the first object after Slice_Start up to and including the object at Slice_End.

Input

[1, 2, 3, 4, 5]

Slice_Start

2

Slice_End

4

Output

[3, 4]


Slice array from start

Returns a slice of the given array, from the first object in the array up until the specified index.

Input

[1, 2, 3, 4, 5]

Slice_End

4

Output

[1, 2, 3, 4]


Slice array to end

Returns a slice of the given array, from the specified index up to, and including the last object.

Input

[1, 2, 3, 4, 5]

Slice_Start

2

Output

[3, 4, 5]


Sort array

Sorts the objects in the given array. Supports strings, numbers, and datetime strings.

Input

["joe", "jane", "jill","bob", "doug","mary" ]

Sort_Order

Ascending

Output

["bob", "doug", "jane", "jill", "joe", "mary"]


Subtract arrays

Compare two arrays (left and right) to receive 3 sub-arrays:

  • Intersection - objects that exist in both arrays.

  • Left_dif - objects that exist only in the first array.

  • Right_dif - objects that exist only in the second array.

Left_Array

["joe", "jane", "jill","bob", "doug","mary", 1, 2, 3 ]

Right_Array

["joe", "jane", "jill","bob", "doug","mary"]

Output

"intersection": ["bob", "doug", "jane", "jill", "joe", "mary"],"left_dif": [3, 1, 2],"right_dif":[]


Unique on array

Returns only unique values from the original array.

Input

["joe", "jane", "jill", "bob", "doug","mary", "jill", "joe"]

Output

["joe", "jane", "jill","bob", "doug","mary", ]

Did this answer your question?