Breadcrumbs

join() Operation

Concatenates all string in an array and separates them by a separator.

Syntax

aStringArray.join(aSeparatorString)

Semantics

Concatenates all strings in aStringArray and separates them by aSeparatorString.

This is a convenience operation that can be used instead of reduce aStringArray using concat(element, aSeparatorString, nextElement) if single use element;.


Substitutables

aStringArray

An Array of String elements. 

aSeparatorString

A separator of type String.

Examples

Join elements of an array of String

Input: an array of names

JSON
{"names": ["Irene", "Eliza", "Raymond", "Jane", "David"]}
set result = names.join(" | ");

Result: result is “Irene | Eliza | Raymond | Jane | David".

Join string elements of a complex array using a helper array

Input: an array of complex articles

JSON
{ "articles": [
    {"name": "AF-1200", "category": "Adapter", "serviceInterval": 52},
    {"name": "CD-2024", "category": "Connector", "serviceInterval": 208},
    {"name": "RC-0002", "category": "Adapter", "serviceInterval": 104},
    {"name": "CD-2002", "category": "Connector", "serviceInterval": 26}
]}
local stringArray = apply element.name to articles;
set result = stringArray.join(", ");

Result:

JSON
{ "stringArray": ["AF-1200", "CD-2024", "RC-0002", "CD-2002"]}

result is “AF-1200, CD-2004, RC-0002, CD-2002”.

📗

Related Pages:

  • reduce Statement
    Reduces an array to a scalar value by recursively applying an expression to each array element and its next element.