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

106
Views
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 answers
Answer question

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 Report

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