Arrays

A reference document listing built-in convenience functions to support data transformation in expressions for arrays.

average(): Number

Returns the value of elements in an array.


chunk(size: Number): Array

Splits arrays into chunks with a length of size.

Function parameters

  • size (REQUIRED, NUMBER) : The size of each chunk.

compact(): Array

Removes empty values from the array.


difference(arr: Array): Array

Compares two arrays.

Returns all elements in the base array that aren't present in arr.

Function parameters

  • arr (REQUIRED, ARRAY) : The array to compare to the base array.

intersection(arr: Array): Array

Compares two arrays.

Returns all elements in the base array that are present in arr.

Function parameters

  • arr (REQUIRED, ARRAY) : The array to compare to the base array.

first(): Array item

Returns the first element of the array.


isEmpty(): Boolean

Checks if the array doesn't have any elements.


isNotEmpty(): Boolean

Checks if the array has elements.


last(): Array item

Returns the last element of the array.


max(): Number

Returns the highest value in an array.


merge(arr: Array): Array

Merges two Object-arrays into one array by merging the key-value pairs of each element.

Function parameters

  • arr (REQUIRED, ARRAY): The array to merge into the base array.

min(): Number

Gets the minimum value from a number-only array.


pluck(fieldName?: String): Array

Returns an array of Objects where keys equal the given field names.

Function parameters

  • fieldName (OPTIONAL, STRING) : The key(s) you want to retrieve.

You can enter as many keys as you want, as comma-separated strings.


randomItem(): Array item

Returns a random element from an array.


removeDuplicates(key?: String): Array

Removes duplicates from an array.

Function parameters

  • key (OPTIONAL, STRING): A key, or comma-separated list of keys, to check for duplicates.

renameKeys(from: String, to: String): Array

Renames all matching keys in the array.

You can rename more than one key by entering a series of comma-separated strings, in the pattern oldKeyName, newKeyName.

Function parameters

  • from (REQUIRED, STRING): The key you want to rename.
  • to (REQUIRED, STRING): The new name.

smartJoin(keyField: String, nameField: String): Array

Operates on an array of objects where each object contains key-value pairs.

Creates a new object containing key-value pairs, where the key is the value of the first pair, and the value is the value of the second pair.

Removes non-matching and empty values and trims any whitespace before joining.

Function parameters

  • keyField (REQUIRED, STRING): The key to join.
  • nameField (REQUIRED, STRING): The value to join.
Example

BASIC USAGE

Copy
Copied
// Input
{{ [{"type":"fruit", "name":"apple"},{"type":"vegetable", "name":"carrot"} ].

---smartJoin("type","name") }}
// Output
[Object: {"fruit":"apple","vegetable":"carrot"}]

sum(): Number

Returns the total sum of all the values in an array of parsable numbers.


toJsonString(): String

Convert an array to a JSON string.

Equivalent of JSON.stringify.


union(arr: Array): Array

Concatenates two arrays and then removes duplicate.

Function parameters

  • arr (REQUIRED, ARRAY) : The array to compare to the base array.

unique(key?: String): Array

Remove duplicates from an array.

Function parameters

  • key (OPTIONAL, STRING) : A key, or comma-separated list of keys, to check for duplicates.