从javascript数组获取变量
我想从Javascript“数组”中获取变量“priceWithVatMin”和“priceWithVatMax”从javascript数组获取变量,javascript,Javascript,我想从Javascript“数组”中获取变量“priceWithVatMin”和“priceWithVatMax” 数据层=[]; dataLayer.push({'shoptet':{ “页面类型”:“productDetail”, “产品”:{ “id”:2148, “名称”:“iPhone7加32GB黑色”, “货币”:“捷克克朗”, “VATMIN价格”:12899, “VATMAX价格”:13599 } 我想要一些类似于在控制台中写入此变量的变量,例如->console.log(?
数据层=[];
dataLayer.push({'shoptet':{
“页面类型”:“productDetail”,
“产品”:{
“id”:2148,
“名称”:“iPhone7加32GB黑色”,
“货币”:“捷克克朗”,
“VATMIN价格”:12899,
“VATMAX价格”:13599
}
我想要一些类似于在控制台中写入此变量的变量,例如->console.log(?)
多谢:-)
其他答案仅访问一项。如果您想获取数组中的每一项(假定您添加了更多项)。
dataLayer[0].shoptet.product.priceWithVatMin
点击F12
,进入控制台,键入数据层
,查看它是什么。然后您可以尝试数组和对象访问来找到所需的路径。这不需要S.O.问题这不是变量,而是
<script>
dataLayer = [];
dataLayer.push({'shoptet' : {
"pageType": "productDetail",
"product": {
"id": 2148,
"name": "iPhone 7 Plus 32GB Black",
"currency": "CZK",
"priceWithVatMin": 12899,
"priceWithVatMax": 13599
}
dataLayer.forEach(item => {
console.log(item.shoptet.product.priceWithVatMin)
})