Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
How to get specific values from an array with data layer

I would like to know the correct function for Google Tag Manager, when you create a Custom JavaScript, how can I get the product "id"("259496742","1061024") when you have an array.

 {
       "0": "event",
       "1": "purchase",
       "2": {
          "transaction_id": "ORD00174",
          "affiliation": "Lightspeed",
          "value": "0.00",
          "currency": "EUR",
          "tax": "0.00",
          "shipping": "0.00",
          "items": [
             {
                "id": 259496742,
                "name": "Haarklem Print",
                "currency": "EUR",
                "brand": "",
                "variant": 259496742,
                "price": "9.95",
                "quantity": 1
             },
             {
                "id": 1061024,
                "name": "Lila Hoed",
                "currency": "EUR",
                "brand": "",
                "variant": 263376478,
                "price": "19.95",
                "quantity": 1
             }
          ],
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can do:

const obj = {
   "0": "event",
   "1": "purchase",
   "2": {
      "transaction_id": "ORD00174",
      "affiliation": "Lightspeed",
      "value": "0.00",
      "currency": "EUR",
      "tax": "0.00",
      "shipping": "0.00",
      "items": [
         {
            "id": 259496742,
            "name": "Haarklem Print",
            "currency": "EUR",
            "brand": "",
            "variant": 259496742,
            "price": "9.95",
            "quantity": 1
         },
         {
            "id": "1061024",
            "name": "Lila Hoed",
            "currency": "EUR",
            "brand": "",
            "variant": 263376478,
            "price": "19.95",
            "quantity": 1
         }
      ],
   }
}

let ids = []

for(const key in obj) {
  const currentValue = obj[key]
  if (Object.prototype.hasOwnProperty.call(currentValue, 'items')) {
    ids = [...ids, ...currentValue.items.map(item => item.id)]
  }
}

console.log(ids)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!