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

183
Views
How to convert a js object into an array?

My data:

{product_quantity: {quantity: 13, code: "AAA", warehouse: "1000",}}

product_quantity is an field from a mongodb json data.

I need to convert it into this:

{"product_quantity": [{"quantity": 13, "code": "AAA", "warehouse": "1000"}]

How can I transform an object into array with its keys and values?

Thanks.

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

0

const data = [quantity];

output; [{quantity: 13, code: "AAA", warehouse: "1000",}];

about 4 years ago · Juan Pablo Isaza Report

0

json you want is not valid , you can use this

let productQuantity={product_quantity:{quantity:13, code:"AAA", warehouse:"1000"}};

productQuantity.product_quantity=[productQuantity.product_quantity];

console.log(JSON.stringify(productQuantity));

result

{"product_quantity":[{"quantity":13,"code":"AAA","warehouse":"1000"}]}
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!