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

192
Views
Filter array object by type and compare key

I have two arrays, in one (aux) I get key and value. In the second array of objects (result)

enter image description here

I have the attribute "correlati" and what I'm looking for is that if the key of the array "aux" is equal to the attribute "correlati" then it pushes that result in a new array that looks like the following :

[{
   correlative: "G-22-1-06",
   content: <Buffer 25 50 44 46 2d 31 2e 34 0a 25 d3 eb e9 e1 0a 31 20 30 20 6f 62 6a 0a 3c 3c 2f 43 72 65 61 74 6f 72 20 28 43 68 72 6f 6d 6d 69 27 50 72 6f 64 ... 277154 more bytes>,
name_Patient: "Jeidi Nicol Matute Banegas"
},
{
  correlative: "G-22-1-07",
   content: <Buffer 25 50 44 46 2d 31 2e 34 0a 25 d3 eb e9 e1 0a 31 20 30 20 6f 62 6a 0a 3c 3c 2f 43 72 65 61 74 6f 72 20 28 43 68 72 6f 6d 6d 69 27 50 72 6f 64 ... 275969 more bytes>,
name_Patient: "Maria Hercilia Noriega"
}
]

code:

 const newArr: bodyEmailSent[] = [];
              const result = attachment.map( element =>  this.getCantidad.find( y => element.content === y.content ) )
              console.log('result', result)
              
              //const aux = this.namePatient.find( y => result.map( element => element.correlativo_solicitud ) === y )
              console.log('Aux', this.namePatient);
             
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can loop through result array and check if array_element["correlative"] exists in aux array as key. So,...

// Your 2 arrays
let result = []
let aux = []

let ans = []
result.forEach(ele=>{
    expected_key = res["correlative"];
    // check if above key is present in aux
    if(aux[expected_key]){
        // crate a copy so items in result also doesn't update
        let newItem={...ele};
        // Add new required key, value
        newItem["name_Patient"]=aux[expected_key]
        // add new item to ans array
        ans.push(newItem)
    }
})

Maybe this is what you wanted

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!