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

155
Views
How to add array on array if id same on react js

I have array like this

const myArr = [
 {
   uuid: 123,
   name: aa
 },
 {
   uuid: 456,
   name: bbb
 }
]

How to add a new array if I call API with UUID above this

example: domain.com/product-option/456

I want this response :

const myArr = [
 {
   uuid: 123,
   name: aa
 },
 {
   uuid: 456,
   name: bbb,
   product-option : [
     {
       uuid:01,
       name: abcd
     }
   ]
 }
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I am assuming when you call an api with any uuid you want to add returned response to that particular item in array.
So lets say you have called api with uuid:456 so you want to include api response into existing array with uuid:456

domain.com/product-option/456

To do that after you get successful api response you can add new property product-option to your existing array myArr using following code -

myArr.forEach((element) => {
  if(element.uuid === uuid){
    element['product-option'] = response.data;
  }
});
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!