[英]JavaScript multiple array objects
我想用Javascript创建此数组,但实际上我在过程中感到震惊。 我在下面给出一个例子:
在生成“产品”列表对象的第二个数组时,我面临一个很大的问题。 能否请大家告诉我如何生成多个产品列表,如下所示。
var dataLayer = [];
dataLayer.push({
'products': [{
'name': 'FTP',
'id': 'TXN_987666',
'price': 123,
'brand': 'ABC',
'category': 'RTP',
'quantity': '4'
}, {
'name': 'CHI',
'id': 'TXN_89798798',
'price': 656,
'brand': 'Fairmont',
'category': 'FMP',
'quantity': 7
}]
}
}
});
.push()语句的末尾有几个额外的花括号。 尝试这个:
<script type="text/javascript"> var dataLayer = []; dataLayer.push({ 'products': [{ 'name': 'FTP', 'id': 'TXN_987666', 'price': 123, 'brand': 'ABC', 'category': 'RTP', 'quantity': '4' }, { 'name': 'CHI', 'id': 'TXN_89798798', 'price': 656, 'brand': 'Fairmont', 'category': 'FMP', 'quantity': 7 }] }); // Test the object contents -- // Click arrows to expand the array members in the console console.log(dataLayer); </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.