Skip to content

entries β€” GTM Variable Template for Object

VARIABLES β€Ί OBJECT
entries EXTENDED Object
Direct (.tpl) Apply (.tpl)

Returns an array of [key, value] pairs from an object.



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
[]

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


πŸ“œ 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