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

151
Visualizações
Check if all the users in an array have at least one element with an ID equal to an array of IDs?

The title is very hard to read, I get it.

I have an array of objects with my users inside of it.

const users = [{
  id: 0,
  name: "Test user 01",
}, {
  id: 1,
  name: "Test user 02"
}, {
  id: 3,
  name: "Test user 03"
}]

const idsToCheck = [2, 4]; 

I want a boolean True if at least one element of users have an ID equal to 2 OR to 4.

I wanted to use Array.some but, with an array to check and not a single value, I cannot loop inside of the method without a lint error.

Thanks

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

0

Some does work.

We are testing numeric IDs against an array of ints - there is reference equality between the IDs and the array elements so the includes is the shortest method over a double some

const users = [{
  id: 0,
  name: "Test user 01",
}, {
  id: 1,
  name: "Test user 02"
}, {
  id: 3,
  name: "Test user 03"
}]

const idsToCheck = [2, 4];

const bool = users.some(({id}) => idsToCheck.includes(id))
console.log(bool)

about 4 years ago · Juan Pablo Isaza Relatório

0

Does this looks OK to you?

const users = [{
  id: 0,
  name: "Test user 01",
}, {
  id: 1,
  name: "Test user 02"
}, {
  id: 3,
  name: "Test user 03"
}]

const idsToCheck = [2, 4];

const isPresent = users.some(user => idsToCheck.some(id => id === user.id));

console.log(isPresent)

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