Expressions and code
Array transformation methods
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 array average throw in a Duaer expression?
In a Duaer expression, average(), max(), min(), and sum() on an array expect numbers. If any element is not a number, those methods throw.
What do unique and removeDuplicates do in Duaer?
In a Duaer expression, unique() and removeDuplicates() drop duplicate elements from an array. pluck(fieldName) takes that field from each object and ignores elements that are not objects or lack the field.
In this section
Define reusable variables in Duaer
Duaer variables store a value for more than one digital organization. Expressions and the Code node read them as $vars.key. Every variable is a string, and a run only reads it.
ExpressionsWrite expressions in Duaer
A Duaer expression sits inside {{ }} and reads the current item, earlier nodes, and variables from a node parameter. When you are only reshaping fields, prepare them in an Edit Fields (Set) node first.
ExpressionsBuilt-in methods and variables in Duaer expressions
Duaer expressions provide variables for reading data and methods you call on a value. The Code node runs plain JavaScript and native Luxon. A method that is a Duaer extension may be missing there, or take different arguments.
ExpressionsConvenience methods in Duaer expressions
Duaer expressions use $json for the current item, $("Node name") for an earlier node, and $now and $if() for time and conditions. These names are available in expression mode on a parameter.
ExpressionsVariables for HTTP node pagination
The Duaer HTTP Request node provides $pageCount, $request, and $response in pagination expressions. Those three names work only in that node. Other nodes cannot read them.
TransformData transformation methods by type
Duaer expressions call transformation methods on a value, such as {{ $json.name.toTitleCase() }}. The methods are grouped by array, boolean, date, number, object, and string. The Code node does not have these extensions.
TransformBoolean transformation methods
In a Duaer expression, a boolean can be tested for empty and converted to a number or a string. true becomes 1 as a number. false becomes 0.
TransformDate transformation methods
In a Duaer expression, $now and $today are Luxon DateTime values. Call toDateTime() on a string or number before format, plus, or setZone.
TransformNumber transformation methods
In a Duaer expression, number methods round, test even or odd, and convert to a boolean, a string, or a DateTime. round goes to the nearest number. ceil goes up. floor goes down.
TransformObject transformation methods
In a Duaer expression, object methods test fields, drop fields, merge objects, and encode an object as a query string. keys() and values() return the field names and the values.
TransformString transformation methods
In a Duaer expression, string methods change case, slice text, test emails and URLs, and encode or decode base64 and URLs. Call the method on the string.
QueryQuery JSON with JMESPath
Duaer queries JSON with $jmespath(object, "query"). Expressions and the JavaScript Code node can call it. The Python Code node does not have this function.
DatesUse Luxon for dates in expressions
Dates in a Duaer expression are Luxon DateTime values. $now and $today are DateTime values already. The Code node uses native Luxon. format() and plus(amount, unit) do not carry over unchanged.
ExamplesDuaer expression examples
These examples run in Duaer expression mode. They read the current item, fill a default, format a date, and move a large reshape into Edit Fields (Set).
ExamplesMethods and variables reference
These are the names used most often in a Duaer expression. The current item is $json, an earlier node is $("Node name"), variables are $vars, and transformation methods are grouped by data type.