Array Transformer
Array transformers can be used on a value data type of Array, including arrays coming from other transformers, such as by using dot notation on a dictionary. Note that all indexes used in dictionaries start from 0. Following transformers are available:
first
firstReturns the first element in the array.
Usage:
.first()Example usage:
array.first()Example:
["bob", "dan", "oleg"]tobob
until
untilReturns first N elements of the array. If the array is not sufficiently long, will return the entire array.
Usage:
.until(n)Example usage:
array.until(2)Example:
["bob", "dan", "oleg"]to["bob", "dan"]
last
lastReturns the last element in the array.
Usage:
.last()Example usage:
array.last()Example:
["bob", "dan", "oleg"]tooleg
from
fromReturns array starting from the Nth element. If the index is beyond bounds, will return an empty array.
Usage:
.from(n)Example usage:
array.from(1)Example:
["bob", "dan", "oleg"]to["dan", "oleg"]
at
atReturns the Nth element of the array.
Usage:
.at(n)Example usage:
array.at(1)Example:
["bob", "dan", "oleg"]todan
range
rangeReturns N elements of the array, starting at index M. If the array is not sufficiently long, will be trimmed from the end.
Usage:
.range(n, m)Example usage:
array.range(1, 1)Example:
["bob", "dan", "oleg"]to["bob"]
random
randomReturns a random element of the array.
Usage:
.random()Example usage:
array.random()Example:
["bob", "dan", "oleg"]tobobor any other element, based on your luck :)
shuffled
shuffledReturns shuffled array.
Usage:
.shuffled()Example usage:
array.shuffled()Example:
["bob", "dan", "oleg"]to["dan", "oleg", "bob"]or any other combination, based on your luck :)
sorted
sortedReturns sorted version of the array. Only works on String or Int arrays, otherwise array remains the same as the source.
Usage:
.sorted()Example usage:
array.sorted()Example:
["bob", "oleg", "dan"]to["bob", "dan", "oleg"]
reversed
reversedReturns reversed version of the array, meaning the first element will be last and vice versa.
Usage:
.reversed()Example usage:
array.reversed()Example:
["bob", "dan", "oleg"]to["oleg", "dan", "bob"]
enumerated
enumeratedReturns dictionary with index-based keys and values of source array. This is very useful for loops to obtain index alongside data for each cycle. Enumeration index starts with 0.
Usage:
.enumerated()Example usage:
array.enumerated()Example:
["bob", "dan"]to[0: "oleg", 1: "dan"]
append
appendReturns array with one additional item pushed into it.
Usage:
.append(item)Example usage:
array.append("dan")Example:
["bob"]to["bob", "dan"]
join
joinReturns string that is made by joining all other strings inside an array, joined by a separator. Will throw an error when the array contains something else than just strings.
Usage:
.join(separator)Example usage:
array.join(", ")Example:
["bob", "dan"]to"bob, dan"
concat
concatReturns array joined with another array.
Usage:
.concat(array)Example usage:
array.contact(["dan"])Example:
["bob"]+["dan"]to["bob", "dan"]
count
countReturns the size of the array.
Usage:
.count()Example usage:
array.count()Example return:
["bob", "dan", "oleg"]to3
Last updated
Was this helpful?