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

83
Views
how to match data from a 2 arrays and create a new array

i have the following array

response=[
    {            
        "mId": "4a993417-3dae-4a85-bb2e-c535d7fda6d7",
        "title": "test2",
        "score": "4",
        "id": "91ce873f-6e58-4c30-86d4-4eb7f200640e"
    }
]
[
    {            
        "mId": "7896548-3dae-4a85-bb2e-c855d7fda6d7",
        "title": "discussion",           
        "score": "18",        
        "id": "91ce873f-6e58-4c30-86d4-4eb7f200640e"
    }
]
[
    {           
        "mId": "20d78952-3dae-4a85-bb2e-c535d7fda6d7",
        "title": "test",         
        "score": "1",          
         "id": "7777777f-6e58-4c30-86d4-4eb7f200640e"
    }
]

i then have another array that looks as follows

mixture=[{"id":"4a993417-3dae-4a85-bb2e-c535d7fda6d7","name":"flour","description":"10g sold"}]
[{"id":"20d78952-3dae-4a85-bb2e-c535d7fda6d7","name":"teabag","description":"stock arriving"}]

how do i check the mId from the response array onto the corresponding array from mixture to get back the name so my new array should look as follows

newArray=[{
"name":"flour"
"mId": "4a993417-3dae-4a85-bb2e-c535d7fda6d7",
            "title": "test2",
            "score": "4",
            "id": "91ce873f-6e58-4c30-86d4-4eb7f200640e"
}]
[{ "name":"flour"
           "mId": "4a993417-3dae-4a85-bb2e-c535d7fda6d7",
            "title": "discussion",           
            "score": "18",        
            "id": "91ce873f-6e58-4c30-86d4-4eb7f200640e"
}]
[{         "name":"testbag"
           "mId": "7896548-3dae-4a85-bb2e-c855d7fda6d7",
            "title": "test",           
            "score": "1",        
            "id": "7777777f-6e58-4c30-86d4-4eb7f200640e"
}]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As long as you write your response and mixture arrays correctly, you can achieve it by using a combination of Array.prototype.map() and Array.prototype.find()

const newArray = response.map(item => {
    const mix = mixture.find(mix => mix.id === item.mId);
    if (mix) {
        item.name = mix.name;
    }
    return 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!