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

112
Vistas
method to check if a specific number with a group of numbers exists within an array in javascript

var numbers = [1, 2, 3, 4, 5, 6, 7, 8];

need to check if 2, 3, 4 exist in the array. Only has to be 1 of these numbers to return true...not all. What's the best approach. I was thinking lodash includes, but I believe I can only pass in a single value.

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

0

Using Array#some and Array#includes:

const hasAny = (arr = [], nums = []) =>
  nums.some(n => arr.includes(n));

console.log( hasAny([1, 2, 3, 4, 5, 6, 7, 8], [2, 3, 4]) );

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you want to get the intersection, you can filter the first array by the second array, or rather, whether or not the second array contains each element of the first. You can see which members were included, or check the size of the new array > 0 if you need a boolean (or use Mr Badawi's .some method).

var numbers = [1, 2, 3, 4, 5, 6, 7, 8];
var needs = [2, 3, 4 ];

var check = numbers.filter(x=>needs.includes(x));
console.log(check);

var numbers = [3, 5, 6, 7, 8, 12, 20];
var needs = [2, 3, 4 ];

var check = numbers.filter(x=>needs.includes(x));
console.log(check);

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