I have a pre-existing array set up like this.
var dataLayer = [];
dataLayer = [{
'transactionProducts': [{
'sku': '96710381',
'name': 'QEH',
'category': 'GLD',
'price': '309.00',
'quantity': '3'
},
{
'sku': '96710382',
'name': 'RYP',
'category': 'FMT',
'price': '209.00',
'quantity': '3'
}]
}];
My goal now is to create another array with all the values from the existing one above. Here's how I've attempted it. However, only the first set of values gets transferred to the new array. The second set doesn't come through in the new array. Would appreciate some insights on how to resolve this issue!
var length = dataLayer[0]['transactionProducts'].length;
var len = dataLayer.length;
var gtmDataLayer = [];
var gtmDataLayer = [];
for (i=0;i<length;i++) {
var zsku = window.dataLayer[0]['transactionProducts'][i].sku;
var zsku = window.dataLayer[0]['transactionProducts'][i].sku;
var zname = window.dataLayer[0]['transactionProducts'][i].name;
var zcat = window.dataLayer[0]['transactionProducts'][i].category;
var zprice = window.dataLayer[0]['transactionProducts'][i].price;
var zquant = window.dataLayer[0]['transactionProducts'][i].quantity;
window.gtmDataLayer.push({
'transactionProducts': [{
'sku': zsku,
'name': zname,
'category': zcat,
'price': zprice,
'quantity': zquant
}]
});
}