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

133
Vistas
Javascript: Is there a way to check if an array contains at least one element from another array?

Is there a way to test whether or not an array contains at least one element from another array?

let array1 = [`a`, `b`, `c`, `d`, `e`];
let array2 = [`c`];

Basically is there a way to determine if array2 has any of the elements from array1 in a single step. I realize I could check to see if array2 has a or b or c or d or e, but I'm curious if there is a method that helps me.

includes() only allows me to check for one value. some() would allow me to test if c is included in array1 but not test if any of the five elements from array1 are part of the array2.

Is there some way of using reduce() or filter()?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could take Array#some with a Set.

const
    array1 = ['a', 'b', 'c', 'd', 'e'],
    array2 = ['c'],
    hasValue = array2.some(Set.prototype.has, new Set(array1));

console.log(hasValue);

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