Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda