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

115
Vistas
Copy array from one array to another and change values while copying

I have two arrays:

dataArray1 = [{
"id":1
"addressDetails": {55:1,56:20}
},
{
"id":2
"addressDetails": {55:30,56:10}
}
]

Above array contains addressDetails as object.

  dataArray2= [{
    "id":1
    "addressDetails": [
     {
      "addressId": "55",
      "city":"london",
      "code":1
     },
      {
      "addressId": "56",
      "city":"paris",
      "code":1
     }
    ]
    },
    {
    "id":2
    "addressDetails": [
     {
      "addressId": "55",
      "city":"london",
      "code":0
     },
      {
      "addressId": "56",
      "city":"paris",
      "code":0
     }
    ]
    }
    ]

This second array contains arrayDetails as array.

In both the arrays, id and addressId will be same. On the basis of both these id's I need to replace addressDetails object in dataArray1 by addressDetails array of dataArray2. In this replacement, I need to change value of "code" property of addressDetails array with the right hand side value(value on right side in addressDetailObject) for that particular id and addressId. For example, for Id "1" and addressId "55", in addressDetails object - "addressDetails": {55:1,56:10} value is "1", so I need to change value of "code" property in addressDetailsArrays with 1 and copy rest attritubtes as it is. How can I do that?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

For this you can run

let result = array1.map((item) => {
    //code to change item here
    //find address value of array2 based on id and addressId
    //replace the code with the address.code details you found above
});

What we are doing here is iterating over items of array1 and returning an updated value for each item.

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