entries β GTM Variable Template for Object
entries EXTENDED Object
Returns an array of [key, value] pairs from an object.
When to Use This
Section titled βWhen to Use ThisβExamples
Section titled βExamplesβObject to entries
INPUT
Object To Process: {name: 'John', age: '30', city: 'Paris'}
OUTPUT
[['name', 'John'], ['age', '30'], ['city', 'Paris']]
Empty object returns empty
INPUT
Object To Process: {}
OUTPUT
[]
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.
entries
Object To Process
πΎ The object whose entries are to be retrieved. If the input is not an object, it will be coerced to an object.
Supported formats:
β Object
β Any (will be coerced)
Supported formats:
β Object
β Any (will be coerced)
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.
Object To Process object
π‘ Type any text to see the result update live
π― Using special value β click input to type instead
Test with:
Falsy
Truthy
π Result Handling β Chain Variables
Chain apply-mode variables to the output. Each variable receives the result of the previous one.
entries()
Related Variables
Section titled βRelated VariablesβSame category: Object
Under the Hood
Section titled βUnder the Hoodβπ View Implementation Code
/** * Retrieves the entries of an object (key-value pairs). * * @param {Object} data.src - The object whose entries are to be retrieved. * @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 getting entries. * * @returns {Array} An array of key-value pairs of the provided object, where each entry is an array [key, value]. * * @framework ggLowCodeGTMKit */const Object = require('Object');const entries = function(objectInput) { return Object.entries(objectInput);};const safeFunction = fn => typeof fn === 'function' ? fn : x => x;const out = safeFunction(data.out);// ===============================================================================// entries - Direct mode// ===============================================================================const applyCast = (castFn, value) => safeFunction(castFn)(value);const value = applyCast(data.pre, data.src);return out(entries(value));// ===============================================================================// entries() β Apply Mode// ===============================================================================/*return function(value) { return out(entries(value));};*/π§ͺ View Test Scenarios (8 tests)
β
'[example] Object to entries'β
Object with numeric values - should return key-value pairsβ
Object with mixed value types - should return key-value pairsβ
'[example] Empty object returns empty'β
Object with array values - should return key-value pairs with arraysβ
Object with nested object values - should return key-value pairs with nested objectsβ
Object with undefined values - should return key-value pairs with undefinedβ
Object with null values - should return key-value pairs with null