Skip to content

some β€” GTM Variable Template for Array

VARIABLES β€Ί ARRAY
some CORE Array
Direct (.tpl) Apply (.tpl)

Returns true if at least one item in the array satisfies the given predicate function.


Array Processing

Iterate, filter, map, and reshape arrays of items for batch data operations.

GA4 Ecommerce

Build and transform ecommerce data structures for GA4 event tracking.


Some match predicate
INPUT
Array To Test: [1, 2, 3, 4, 5]
Predicate Function: function(x) { return x > 3; }
OUTPUT
true
None match predicate
INPUT
Array To Test: [1, 2, 3]
Predicate Function: function(x) { return x > 10; }
OUTPUT
false

This is what you'll see when you open this variable in Google Tag Manager. Hover the icons for details.

some
Array To Test
πŸ’Ύ The array of values to test against the predicate function.

Supported formats:
  βœ“ Array
Predicate Function
πŸ’Ύ A predicate function that receives each value and returns true or false.

Supported formats:
  βœ“ Function
Input Setup
Input Function (optional)
βš™οΈ Optional pre-processing function applied to the input before internal logic (e.g., convert object to string, normalize case). Internal transformations such as case handling will still apply afterward.
Result Handling
Output Function (optional)
βš™οΈ Optional function to apply to the result before returning it (e.g., str => str + ' €', val => val !== undefined for boolean conversion). Useful for chaining transformations on the output.
Array To Test array
πŸ’‘ Type any text to see the result update live
🎯 Using special value β€” click input to type instead
Test with:
Falsy
Truthy
Predicate Function function
some()


πŸ“œ View Implementation Code
/**
* Returns true if at least one item in the array satisfies the given predicate function.
*
* @param {Array} data.src - The array of values to test.
* @param {Function} data.prd - A predicate function that receives each value and returns true or false.
* @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 src before testing.
*
* @returns {boolean} True if at least one value passes the predicate, false otherwise or if input is invalid.
*
* @framework ggLowCodeGTMKit
*/
const getType = require('getType');
const some = function(arr, predicate) {
if (getType(arr) !== 'array' || typeof predicate !== 'function') {
return false;
}
return arr.some(predicate);
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// some - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(some(value, data.prd));
// ===============================================================================
// some(...) – Apply Mode
// ===============================================================================
/*
return function(value, predicate) {
predicate = data.rp1 ? predicate : data.prd;
return out(some(value, predicate));
};
*/
πŸ§ͺ View Test Scenarios (5 tests)
βœ… '[example] Some match predicate'
βœ… '[example] None match predicate'
βœ… Array with strings matching predicate - returns true
βœ… Empty array - returns false
βœ… Non-array input - returns false