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

143
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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