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

99
Views
javascript object Assignment an array

i have an object and with specific key a assign an array

denemeobject['items'] = Object.values(
                  JSON.parse(results.rows.item(index).BarcodeArray),
                );

problem is it looks like this :

"items": [
        [
          {
            "barcode": "1245124125412",
            "qty": 3
          },
          {
            "barcode": "1254123151231",
            "qty": 1
          },
          {
            "barcode": "2352341241241",
            "qty": 1
          },
          {
            "barcode": "1241251241254",
            "qty": 1
          }
        ]
      ]

when i get data it comes to me in array. but assign to in object it caused it array in array. is that normal or there is something off

should be look like this :

[
    {
      "barcode": "1245124125412",
      "qty": 3
    },
    {
      "barcode": "1254123151231",
      "qty": 1
    },
    {
      "barcode": "2352341241241",
      "qty": 1
    },
    {
      "barcode": "1241251241254",
      "qty": 1
    }
  ]

how am i supposed to do that ? any ideas?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You don't need Object.values, just dereference the BarcodeArray property. You then have a plain array of objects containing barcode and qty properties, as you suggested you required.

const data = `{"BarcodeArray":[{"barcode":"1245124125412","qty":3},{"barcode":"1254123151231","qty":1},{"barcode":"2352341241241","qty":1},{"barcode":"1241251241254","qty":1}]}`

console.log(JSON.parse(data).BarcodeArray)

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!