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

66
Views
Adding additional properties to API results in React

I am making an API call in React and I would like to add an additional price property to the results, with each property having a different value for each result.

For example...

API response:

 {
     id: 456
     name: "capuccino",
     type: "coffee",
  },
  {
     id: 457
     name: "latte",
     type: "coffee",
  },
  {
     id: 458
     name: "americano",
     type: "coffee",
   }

Is there a way to dynamically add an additional price property, each with a different value to get the result below?

  {
     id: 456
     name: "capuccino",
     type: "coffee",
     **price: 5.99**   
  },
  {
     id: 457
     name: "latte",
     type: "coffee",
     **price: 10.00**
  },
  {
     id: 458
     name: "americano",
     type: "coffee",
     **price: 8.90**
   }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could create a prices array and use map() and the index to map the price to the correct object.

const response = [{
    id: 456,
    name: "capuccino",
    type: "coffee",
  },
  {
    id: 457,
    name: "latte",
    type: "coffee",
  },
  {
    id: 458,
    name: "americano",
    type: "coffee",
  }
];

const prices = [2, 5, 27];

const result = response.map((o, i) => ({ ...o, price: prices[i] }));

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!