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

267
Views
JavaScript - Check if value is already included in an array with sub-values

I have an array that has sub-values for each value of the array and I am trying to check if a sub-value already exists within the array. Normally I would just use array.includes() but that isn't working in this case. How would I check for sub-values? Here's what I mean:

The array structure: enter image description here

What I tried:

if (dataArray.includes(`classCRN: ${classesArray[i]}`) === false) {
  // ...rest of code...
}
about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

You can use the array.some() method to check it there are the same sub-values.

if(dataArray.some(item => item.classCRN == classesArray[i])){
......
}
about 4 years ago · Santiago Gelvez Report

0

Just loop through array to find property:

let arr = [
    {name: 'test', origin: 'something', value: 'bb123'},
    {country: 'Serbia', city: 'Belgrade'},
    {something: 'here', hey: 'there'}
]
console.log(isInnArray(arr,'there')) //true
console.log(isInnArray(arr,'mystring')) //false

function isInnArray(arr, findMe) {
    for(let i = 0; i < arr.length; i++) {
        for (const [key, value] of Object.entries(arr[i])) {
            if(value===findMe)
                return true
        }
    }
    return false;
}

about 4 years ago · Santiago Gelvez 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!