title: How to return an entire array from datalayer as an array in Google Tag Manager?
body: <p>I have an array in the datalayer I would like to access as a variable in Google Tag Manager.  I want the entire array though, not just a value from a specific property...</p>
  
  <p>I am trying to fire an eCommerce track like this:</p>
  
  <pre><code>&lt;script&gt;
  analytics.track(‘Product List Viewed’, {
  list_id: ‘Products List’,
  products:
  ‘{{productListArray}}’
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>The {{productListArray}} variable, a custom javascript type GTM variable, I would like to return the full array from the datalayer variable called {{productList}}, which is a datalayer variable, with variable type of Array in the GTM debugger, that has this value:</p>
  
  <pre><code>[
  {
  product_id: ‘132699’,
  sku: ‘Brand Name - 132699’,
  brand: ‘Brand Name’,
  name: ‘Product Name 1’,
  price: 1.00,
  position: 1,
  category: ‘category2’,
  },{
  product_id: ‘132702’,
  sku: ‘Brand Name - 132702’,
  brand: ‘Brand Name’,
  name: ‘Product Name 2’,
  price: 1.00,
  position: 2,
  category: ‘category1’
  }
  ]
  </code></pre>
  
  <p>I have been able to pull out a list of specific elements of the array, like product_id, using this method:</p>
  
  <pre><code>function() {
    var products = {{productList}};
    return products.map(function(prod) { return prod.product_id; });
  </code></pre>
  
  <p>...but I’d like to know the best approach for getting the entire array, with all objects in their entirety, so I can push the entire thing as a single variable in my Product List View track call.
  I could probably store the array as text when pushed to the datalayer, but that seems like a bad workaround. How do I pull in the entire array of objects instead of just the values for a specific field?</p>
  
  <hr>
  
  <p>UPDATE 12-4 - to add how the datalayer push looks like:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>dataLayer.push({
      'event': 'productListViewed',
      'productList': [{
          'product_id': 132699,
          'sku': 'Brand Name - 132699',
          'brand': 'Brand Name',
          'name': 'Product Name 1',
          'price': 1.00,
          'position': 1,
          'category': 'category2'
      }, {
          'product_id': 132702,
          'sku': 'Brand Name - 132702',
          'brand': 'Brand Name',
          'name': 'Product Name 2',
          'price': 1.00,
          'position': 2,
          'category': 'category1'
      }]
  })</code></pre>
  </div>
  </div>
  </p>