every β GTM Variable Template for Array
every CORE Array
Returns true if all items in the array satisfy 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βAll match predicate
INPUT
Array To Test: [2, 4, 6, 8]
Predicate Function: function(x) { return x % 2 === 0; }
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; }
Predicate Function: function(x) { return x % 2 === 0; }
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.
every
Array To Test
πΎ The array of values to evaluate 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.
every()
Related Variables
Section titled βRelated VariablesβSame category: Array
Under the Hood
Section titled β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 ? predicate : data.prd; 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