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

98
Views
react native creating object with arrays

i have arrays like this:

[
0: {barcode: '4124121241241', qty: 1}
1: {barcode: '1234124135134', qty: 1}
2: {barcode: '3573424625234', qty: 1}
3: {barcode: '2346468457354', qty: 1}
4: {barcode: '5684452043432', qty: 1}
5: {barcode: '1241263475686', qty: 5}
6: {barcode: '1231241231423', qty: 15}
]

and i'm pushing those like this:

shelfArray.push({
    [rafName]:JSON.parse(results.rows.item(index).BarcodeArray)
});

this is my output:

0:
Q1:
BarcodeArray: [{…}]
1:
Q2:
BarcodeArray: (7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
2: {Q3: null}

but i want this like :

Q1:
BarcodeArray: [{…}]
Q2:
BarcodeArray: (7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
2: {Q3: null}

how can do that ?

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

0

Rather than creating shelfArray as an array [], create it as an empty object

const shelfArray = {}; // rather than `= [];`

and then add keys to that object as you loop instead of pushing by using bracket notation:

shelfArray[rafName] = JSON.parse(results.rows.item(index).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!