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

136
Views
Cambie el valor del objeto en la matriz si la identificación del objeto tiene una propiedad propia en otra identificación del objeto

estos son mis datos

 let a = [ { "activityCode": "23", "isValid": null }, { "activityCode": "28", "isValid": null }, { "activityCode": "32", "isValid": null } ] let b = [ { "activityCode": "23", "allocated": 3 }, { "activityCode": "32", "allocated": 2 } ]

Quiero cambiar "isValid" a verdadero si el código de actividad (a) en la matriz tiene el mismo código de actividad (b) y "es válido" a falso si el código de actividad (a) en la matriz no tiene el mismo código de actividad (b), y la salida que necesito como esto:

 let a = [ { "activityCode": "23", "isValid": true }, { "activityCode": "28", "isValid": false }, { "activityCode": "32", "isValid": true } ]

Por favor, ayúdame. gracias chicos.

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

0

 a.map(aa => { const match = b.find(bb => bb.activityCode === aa.activityCode); return { activityCode: aa.activityCode, isValid: match !== undefined }; })

about 4 years ago · Juan Pablo Isaza Report

0

Prueba esto :

 a.forEach(element => { element.isValid = b.some(e => e.activityCode === element.activityCode); }); console.log(a);
about 4 years ago · Juan Pablo Isaza Report

0

Puede usar Array.map() y Array.some() para obtener el resultado deseado. Si algún elemento de a está presente en la matriz b, Array.some() devolverá verdadero.

 let a = [ { "activityCode": "23", "isValid": null }, { "activityCode": "28", "isValid": null }, { "activityCode": "32", "isValid": null } ] let b = [ { "activityCode": "23", "allocated": 3 }, { "activityCode": "32", "allocated": 2 } ] const result = a.map(({ activityCode }) => ({ activityCode, isValid: b.some(el => el.activityCode === activityCode ) })); console.log('Result:', result)
 .as-console-wrapper { max-height: 100% !important; top: 0; }

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!