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
first
Returns the first element in the array.
Usage:
.first()
Example usage:
array.first()
Example:
["bob", "dan", "oleg"]
tobob
until
until
Returns 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
last
Returns the last element in the array.
Usage:
.last()
Example usage:
array.last()
Example:
["bob", "dan", "oleg"]
tooleg
from
from
Returns 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
at
Returns the Nth element of the array.
Usage:
.at(n)
Example usage:
array.at(1)
Example:
["bob", "dan", "oleg"]
todan
range
range
Returns 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
random
Returns a random element of the array.
Usage:
.random()
Example usage:
array.random()
Example:
["bob", "dan", "oleg"]
tobob
or any other element, based on your luck :)
shuffled
shuffled
Returns 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
sorted
Returns 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
reversed
Returns 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
enumerated
Returns 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
append
Returns array with one additional item pushed into it.
Usage:
.append(item)
Example usage:
array.append("dan")
Example:
["bob"]
to["bob", "dan"]
join
join
Returns 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
concat
Returns array joined with another array.
Usage:
.concat(array)
Example usage:
array.contact(["dan"])
Example:
["bob"]
+["dan"]
to["bob", "dan"]
count
count
Returns the size of the array.
Usage:
.count()
Example usage:
array.count()
Example return:
["bob", "dan", "oleg"]
to3
Last updated
Was this helpful?