join — GTM Variable Template for Array
join CORE Array
Joins the elements of an array into a single string, with an optional separator between each element.
When to Use This
Array Processing
Iterate, filter, map, and reshape arrays of items for batch data operations.
Combining
Merge, concatenate, or join multiple values into a unified result.
Examples
Join with comma
INPUT
Array to Join: ['apple', 'banana', 'orange']
Separator (use {{space}} for space, blank for no separator): ,
Separator (use {{space}} for space, blank for no separator): ,
OUTPUT
apple,banana,orange
Non-array returns undefined
INPUT
Array to Join: not an array
Separator (use {{space}} for space, blank for no separator): ,
Separator (use {{space}} for space, blank for no separator): ,
OUTPUT
undefined
GTM Configuration
This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.
join
Array to Join
💾 The array of elements to join into a string.
Supported formats:
✓ Array variable: {{myArrayVariable}}
✓ Array literal: ["a", "b", "c"]
Supported formats:
✓ Array variable: {{myArrayVariable}}
✓ Array literal: ["a", "b", "c"]
Separator (use {{space}} for space, blank for no separator)
💾 The separator string to place between array elements. Spaces are trimmed in GTM fields, so use
Supported formats:
✓ String (use {{space}}for space)
✓ Empty string (no separator)
{{space}} to represent a space character.Supported formats:
✓ String (use {{space}}for space)
✓ Empty string (no separator)
Input Setup
Input Function (optional)
⚙️ Optional pre-processing function applied to the array before joining (e.g., filter empty values, transform elements).
Result Handling
Output Function (optional)
⚙️ Optional function to apply to the joined string before returning it (e.g.,
str => str.toUpperCase(), str => str.trim()). Useful for chaining transformations on the output.Array to Join array
💡 Type any text to see the result update live
🎯 Using special value — click input to type instead
Test with:
Falsy
Truthy
Separator (use {{space}} for space, blank for no separator) string
🔗 Result Handling — Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
join()
Related Variables
Same category: Array
Under the Hood
📜 View Implementation Code
/**
* Joins the elements of an array into a single string, with an optional separator between each element.
*
* @param {Array} data.arr - The array of elements to join.
* @param {string} data.sep - The separator to use between elements.
* @param {Function|string} [data.out] - Optional output handler: function to transform result or string with format.
*
* Direct-mode specific parameters:
* @param {Function} [data.pre] - Optional pre-processor function to transform arr before joining.
*
* @returns {string|undefined} The joined string if the input is an array, or undefined if the input is not an array.
*
* @framework ggLowCodeGTMKit
*/
const getType = require('getType');
const join = function(array, separator) {
if (getType(array) === 'array') {
return array.join(separator);
}
return undefined;
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// join - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const processedArray = applyCast(data.pre, data.arr);
return out(join(processedArray, data.sep));
// ===============================================================================
// join(...) – Apply Mode
// ===============================================================================
/*
return function(value, separator) {
return out(join(value, data.sep));
};
*/🧪 View Test Scenarios (5 tests)
✅ '[example] Join with comma'
✅ Test joining array with space separator
✅ Test joining array with no separator (empty string)
✅ '[example] Non-array returns undefined'
✅ Test joining array with mixed types