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

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

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 Report

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