Duaer

Expressions and code

Array transformation methods in Duaer

In a Duaer expression, call an array method on the array, such as {{ $json.ids.unique() }}. average, max, and min throw if any element is not a number.

Call them in a Duaer expression

These methods run on an array. Some are Duaer extensions. The Code node does not have the same names.

Methods

  • append(...elements) adds elements at the end and returns the array.
  • average() is the mean of the numbers. A non-number throws.
  • chunk(length) splits the array into sub-arrays of that length.
  • compact() removes null, empty strings, and undefined.
  • concat(...arrays) joins arrays onto the end.
  • difference(otherArray) keeps elements that are in this array and not in the other.
  • filter(fn) keeps elements for which the function returns true.
  • find(fn) returns the first match, or undefined. Use filter() for every match.
  • first() and last() return the first and last elements.
  • includes(element) and indexOf(element) test membership and the first position. A miss is -1. Positions start at 0.
  • intersection(otherArray) keeps elements present in both arrays.
  • isEmpty() and isNotEmpty() treat no elements, null, and undefined as empty.
  • join(separator) builds one string. It is the opposite of split().
  • length is the number of elements.
  • map(fn) builds a new array by applying the function to each element.
  • max() and min() return the largest and smallest number. A non-number throws.
  • pluck(...fieldNames) takes those fields from each object. Elements that are not objects, or lack the field, are ignored.
  • randomItem() returns one element at random.
  • reduce(fn, initial) folds the array into one value.
  • removeDuplicates(keys) and unique() drop duplicate elements.
  • renameKeys(from, to) renames fields on objects in the array. Extra pairs rename more fields.
  • reverse() reverses the order.
  • slice(start, end) returns a section.
  • smartJoin(keyField, valueField) builds one object from objects that each hold a key and a value.
  • sort(compare) sorts strings with no argument. Numbers and objects need a compare function.
  • sum() adds the numbers.
  • mergeIntoObject(otherArray) merges two arrays of objects by key. If the lengths differ, extra elements from the longer array are kept.
  • toJsonString() returns a JSON string.
  • toSpliced(start, deleteCount, ...elements) inserts or removes at a position and returns a new array.
  • toString() joins with commas. Use join() for another separator.
  • union(otherArray) combines both arrays and drops duplicates.

Questions

When does average throw in a Duaer expression?

In a Duaer expression, average(), max(), min(), and sum() expect numbers. If any element is not a number, they throw.

What do unique and removeDuplicates do in Duaer?

In a Duaer expression, they drop duplicate elements. pluck(fieldName) takes that field from each object and ignores elements that are not objects or lack the field.

In this section