Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
How to combine and filter array property's by another arrays property

How can I combine both arrays (profile and countries), but filter any objects where the Name is the same in both arrays (but only remove the object that has IsDirector: null)

I'm guessing it's a combination of concat & filter but not sure how to get it working.

Data:

let profile = [
   {
      "IsDirector":true,
      "Name":"Germany"
   },
   {
      "IsDirector":false,
      "Name":"Spain"
   },
]

let countries = [
   {
      "IsDirector":null,
      "Name":"Germany"
   },
   {
      "IsDirector":null,
      "Name":"Spain"
   },
   {
      "IsDirector":null,
      "Name":"Portugal"
   }
]

Desired result:

 [
       {
          "IsDirector":true,
          "Name":"Germany"
       },
       {
          "IsDirector":false,
          "Name":"Spain"
       },
       {
          "IsDirector":null,
          "Name":"Portugal"
       }
    ]
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Convert the first array into an object for better access and use map

const profile = [
   {
      "IsDirector":true,
      "Name":"Germany"
   },
   {
      "IsDirector":false,
      "Name":"Spain"
   },
]

const countries = [
   {
      "IsDirector":null,
      "Name":"Germany"
   },
   {
      "IsDirector":null,
      "Name":"Spain"
   },
   {
      "IsDirector":null,
      "Name":"Portugal"
   }
]

function f() {
  const p = Object.fromEntries(profile.map(el => ([el.Name, el])));
  return countries.map(el => ({ ...el, IsDirector: p[el.Name]?.IsDirector ?? null }));
}

console.log(f());

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda