Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
método para verificar si existe un número específico con un grupo de números dentro de una matriz en javascript

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

necesita verificar si 2, 3, 4 existen en la matriz. Solo tiene que ser 1 de estos números para que sea verdadero... no todos. ¿Cuál es el mejor enfoque? Estaba pensando en incluir lodash, pero creo que solo puedo pasar un solo valor.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Usando Array#some y 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 Report

0

Si desea obtener la intersección, puede filtrar la primera matriz por la segunda matriz, o más bien, si la segunda matriz contiene o no cada elemento de la primera. Puede ver qué miembros se incluyeron o verificar el tamaño de la nueva matriz> 0 si necesita un valor booleano (o usar el método .some de Mr Badawi).

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!