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

172
Visualizações
Check if an array of object is exactly equal to another array that contains one of its property

I have these 2 arrays The first one is fixed and does not change and contains the id of the 2nd array:

fixed=["123","456","789"] 

The second can change

variableArray=[{name:"Joe",id:"123"},{name:"Joe",id:"456"},{name:"Joe",id:"789"}]

I want to return true if, even if there were some changes at the end the variable array is the same length and contains exactly the same keys of the "fixed"

NOT VALID:

fixed=["123","456","789"] 
variableArray=[{name:"Joe",id:"456"},{name:"Joe",id:"789"}] 

return false because is missing the id "123" (and the length is also different so is excluded by default)

NOT VALID:

fixed=["123","456","789"] 

variableArray=[{name:"Joe",id:"123"},{name:"Joe",id:"456"},{name:"Joe",id:"001"}]

this will return false because, even if contains 3 elements as there are in the "fixed" is missing the id "789" and have another "001" instead

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

as @mplungjan mentiond, you can use Every:

let fixed = ["123", "456", "789"];
let variableArray1 = [{
  name: "Joe",
  id: "123"
}, {
  name: "Joe",
  id: "456"
}, {
  name: "Joe",
  id: "789"
}];
let variableArray2 = [{
  name: "Joe",
  id: "123"
}, {
  name: "Joe",
  id: "456"
}, {
  name: "Joe",
  id: "001"
}]


let containsAll1 = variableArray1.every(elem => fixed.includes(elem.id));
let containsAll2 = variableArray2.every(elem => fixed.includes(elem.id));

console.log(containsAll1, containsAll2);

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