-4

I'm want to get variable "priceWithVatMin" and "priceWithVatMax" from Javascript "array"

     <script>
dataLayer = [];
dataLayer.push({'shoptet' : {
    "pageType": "productDetail",
    "product": {
        "id": 2148,
        "name": "iPhone 7 Plus 32GB Black",
        "currency": "CZK",
        "priceWithVatMin": 12899,
        "priceWithVatMax": 13599
    }

i want some like write in console this variable e.g -> console.log(?) Thanks lot :-)

Kuba Hon
  • 13
  • 5
  • 1
    `dataLayer[0].shoptet.product.priceWithVatMin` – Pac0 Feb 07 '19 at 22:32
  • 2
    Hit `F12`, go to Console, type `dataLayer` and see what it is. You can then try array and object access to find the path you need. This should not require a S.O. question – Taplar Feb 07 '19 at 22:32
  • That's not a variable, that's an [object property](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Basics) – Jon P Feb 07 '19 at 22:36

1 Answers1

-1
dataLayer.forEach(item => {
  console.log(item.shoptet.product.priceWithVatMin)
})

Other answers are accessing just the one item. This is if you want to get every item in the array (presuming you add more).

Adam Specker
  • 425
  • 3
  • 14