Skip to content

some — GTM Variable Template for Array

VARIABLES › ARRAY
some CORE Array

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


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

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

GTM Configuration

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()


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 ? data.prd : predicate;
   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