some β GTM Variable Template for Array
some CORE Array
Returns true if at least one item in the array satisfies the given predicate function.
When to Use This
Section titled βWhen to Use Thisβ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.
Examples
Section titled βExamplesβSome match predicate
INPUT
Array To Test: [1, 2, 3, 4, 5]
Predicate Function: function(x) { return x > 3; }
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; }
Predicate Function: function(x) { return x > 10; }
OUTPUT
false
Live Sandbox
Section titled βLive Sandboxβ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
Supported formats:
β Array
Predicate Function
πΎ A predicate function that receives each value and returns true or false.
Supported formats:
β Function
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
π Result Handling β Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
some()
Related Variables
Section titled βRelated VariablesβSame category: Array
Under the Hood
Section titled βUnder the Hoodβπ 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