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

120
Views
Adding a property to an array of objects

I have an array of objects as shown below

Array(2)
0: "104635ac-4b9a-3f7a-d4f8-e8badca83d58"
1: "547d57b7-ddc7-a481-95e4-ccfe2a6404a8"

I want to add two more properties one named productId and one name quantity to each element of this array of Objects.

The final outcome should be as follows.

  {
    "productId": "104635ac-4b9a-3f7a-d4f8-e8badca83d58",
    "quantity": 1,
  },
  {
    "productId": "547d57b7-ddc7-a481-95e4-ccfe2a6404a8",
    "quantity": 1,
  }

Can someone please let me know how to achieve this?

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

0

You can use Array.map to map through the array and construct an object:

const arr = ["104635ac-4b9a-3f7a-d4f8-e8badca83d58","547d57b7-ddc7-a481-95e4-ccfe2a6404a8"]

const result = arr.map(e => ({quantity: 1, productId: e}))

console.log(result)

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!