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

110
Views
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 answers
Answer question

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 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!