Skip to content

every — GTM Variable Template for Array

VARIABLES › ARRAY
every CORE Array

Returns true if all items in the array satisfy 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

All match predicate
INPUT
Array To Test: [2, 4, 6, 8]
Predicate Function: function(x) { return x % 2 === 0; }
OUTPUT
true
Not all match
INPUT
Array To Test: [2, 4, 5, 8]
Predicate Function: function(x) { return x % 2 === 0; }
OUTPUT
false

GTM Configuration

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

every
Array To Test
💾 The array of values to evaluate 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
every()


Under the Hood

📜 View Implementation Code
/**
* Returns true if every item in the input array satisfies the given predicate function.
* 
* @param {Array} data.src - The array of values to evaluate.
* @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 evaluation.
* 
* @returns {boolean} True if all values pass the predicate, false otherwise or if input is invalid.
*
* @framework ggLowCodeGTMKit
*/
const getType = require('getType');
const every = function(arr, predicate) {
   if (getType(arr) !== 'array' || typeof predicate !== 'function') {
       return false;
   }
   return arr.every(predicate);
};
const safeFunction = fn => typeof fn === 'function' ? fn : x => x;
const out = safeFunction(data.out);
// ===============================================================================
// every - Direct mode
// ===============================================================================
const applyCast = (castFn, value) => safeFunction(castFn)(value);
const value = applyCast(data.pre, data.src);
return out(every(value, data.prd));

// ===============================================================================
// every(...) – Apply Mode
// ===============================================================================
/*
return function(value, predicate) {
  predicate = data.rp1 ? data.prd : predicate;
  return out(every(value, predicate));
};
*/
🧪 View Test Scenarios (8 tests)
✅ '[example] All match predicate'
✅ '[example] Not all match'
✅ Empty array - should return true
✅ All strings pass length check - should return true
✅ Not all strings pass length check - should return false
✅ Non-array input - should return false
✅ Null input - should return false
✅ Non-function predicate - should return false