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

144
Views
How to check if the array inside object has elements of interest?

Hi i have an object like so,

const obj = {
    id: '1',
    itemData: [
        "type1",
        "type2",
        "type3",
    ],
}

sometimes this itemData array can be empty array.

now i have to check if itemData has "type1" or "type2". if so then should return true if not false.

i have tried like below,

const isDisabled = obj.itemData.map(e => return e === "type1" || e==="type2")

but this doesnt work. could someone help me with this. thanks.

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

0

You can use includes with some

const obj = {
    id: '1',
    itemData: [
        "type1",
        "type2",
        "type3",
    ],
}

console.log(!obj.itemData.length || obj.itemData.some(el => ['type1', 'type2'].includes(el)));

The some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns true if, in the array, it finds an element for which the provided function returns true; otherwise it returns false. It doesn't modify the array.

MDN - some

The includes() method determines whether an array includes a certain value among its entries

MDN - includes

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!