Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda