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

134
Views
¿Hay alguna forma de comparar 2 ID de matriz usando reducir Javascript?

Se supone que tengo dos matrices

 // item01 [ { value: "0", value: "01", display: "Jamsheer", key: "jam" }, { value: "1", value: "02", display: "Muhammed", key: "muh" }, { value: "2", value: "03", display: "Ravi", key: "rav" }, { value: "3", value: "04", display: "Ajmal", key: "ajm" }, { value: "4", value: "05", display: "Ryan", key: "rya" } ] // item02 [ { value: "0", value: "01", display: "Kamal" }, { value: "1", value: "02", display: "Jamal"}, ]

El resultado final que necesito es la diferencia entre estas matrices usando id & value y mostrar item02: display, ID & item01: key – el resultado final debería ser así:

 [ { value: "0", value: "01", display: "Kamal", key: "jam"}, { value: "1", value: "02", display: "Jamal", key: "muh"}, ]

Intenté filter con some método pero no resolvió mi problema. ¿Es posible hacer algo como esto usando reducir en JavaScript?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Observe que tiene matrices con objetos que tienen propiedades de value repetidas

  • He modificado el primer value s a id

Creo que lo que quieres es algo como esto:

 // item01 const item01 = [ { id: "0", value: "01", display: "Jamsheer", key: "jam" }, { id: "1", value: "02", display: "Muhammed", key: "muh" }, { id: "2", value: "03", display: "Ravi", key: "rav" }, { id: "3", value: "04", display: "Ajmal", key: "ajm" }, { id: "4", value: "05", display: "Ryan", key: "rya" } ] // item02 const item02 = [ { id: "0", value: "01", display: "Kamal" }, { id: "1", value: "02", display: "Jamal"}, ] const item01Hash = item01.reduce((a, c) => { a[`${c.id}${c.value}`] = c return a }, {}) const result = item02.reduce((a, c) => { const { key } = item01Hash[`${c.id}${c.value}`] return key ? [...a, { ...c, key }] : a }, []) console.log(result)

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!